Ho questa classe "using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using System.Data.Common;
using Abletech.Utility;
using System.Drawing;
using Abletech.Arxivar.Entities;

namespace AbleTech.DBToFileSystem
{
    class ARXDBSQLClass
    {
        private SqlConnectionStringBuilder builder;
        private DbConnection _dbConnection;
        private DbProviderFactory _dbProviderFactory;
        private configurationClass _config;

        public ARXDBSQLClass(configurationClass _config)
        {
            this._config = _config;
            builder = new SqlConnectionStringBuilder();
            builder.DataSource = _config.SQLSERVERHost;
            builder.UserID = _config.SQLSERVERUser;
            builder.Password = _config.SQLSERVERPassword;
            builder.InitialCatalog = _config.SQLSERVERDB;

            this._dbProviderFactory = getDbProviderFactory("System.Data.SqlClient");
            this._dbConnection = DBConnect(@"Server=" + _config.SQLSERVERHost + ";Database=" + _config.SQLSERVERDB + ";User Id="+ _config.SQLSERVERUser + ";Password=" + _config.SQLSERVERPassword + ";");

        }

        #region DB - Connection

        private DbProviderFactory getDbProviderFactory(string DBProvider)
        {
            try
            {
                DbProviderFactory factory = DbProviderFactories.GetFactory(DBProvider);

                return factory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private DbConnection DBConnect(string ConnectionString)
        {
            try
            {

                DbConnection _connection = this._dbProviderFactory.CreateConnection();
                _connection.ConnectionString = ConnectionString;
                _connection.Open();

                return _connection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void checkDBConnection(DbConnection _connection)
        {
            if (_connection.State.Equals(ConnectionState.Closed))
                _connection.Open();
        }
        #endregion

        #region Load - DM_PROFILE
        public List<dmProfile> loadDM_PROFILE()
        {
            try
            {
                checkDBConnection(_dbConnection);

                List<dmProfile> dmProfile = new List<dmProfile>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT DOCNUMBER, CREATION_DATE, FILENAME, ORIGINALE, REVISIONE, IMPRONTA, CSTRING, COMPRESSIONMODE, AOO, PSWZIP ");
                sb.Append("FROM DM_PROFILE ");
                sb.Append("WHERE CSTRING <> '' ");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmProfileItem = new dmProfile()
                            {
                                _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["DOCNUMBER"]),
                                storeDate = System.Convert.ToDateTime(reader["CREATION_DATE"]),
                                fileName = reader["FILENAME"].ToString(),
                                originale = reader["ORIGINALE"].ToString(),
                                revisione = System.Convert.ToInt32(reader["REVISIONE"]),
                                impronta = reader["IMPRONTA"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString()
                            };

                            dmProfile.Add(_dmProfileItem);
                        }
                    }
                }



                return dmProfile;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Update - DM_PROFILE

        public void UpdateDMProfile(int DocNumber, string path)
        {
            try
            {
                checkDBConnection(_dbConnection);

                StringBuilder sb = new StringBuilder();

                sb.Append("UPDATE DM_PROFILE ");
                sb.Append("SET PATH = @path, CSTRING = '' ");
                sb.Append("WHERE DOCNUMBER = @DocNumber ");
                String sqlQuery = sb.ToString();

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                var docNumberParameter = command.CreateParameter();
                docNumberParameter.ParameterName = "@DocNumber";
                docNumberParameter.Value = DocNumber;

                command.Parameters.Add(docNumberParameter);

                var pathParameter = command.CreateParameter();
                pathParameter.ParameterName = "@path";
                pathParameter.Value = path;

                command.Parameters.Add(pathParameter);

                DbTransaction transaction = _dbConnection.BeginTransaction();
                command.Transaction = transaction;

                try
                {
                    command.ExecuteNonQuery();
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw (new Exception("Errore in transazione" + ex.Message));
                }



            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        #endregion

        #region Load - DM_REVISIONI
        public List<dmRevisioni> loadDM_REVISIONI()
        {
            try
            {

                List<dmRevisioni> dmRevisioni = new List<dmRevisioni>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT DM_REVISIONI.ID, DM_REVISIONI.NumDoc, DM_REVISIONI.DataProf, DM_REVISIONI.NomeFile, DM_REVISIONI.ORIGINALE, DM_REVISIONI.Revisione, DM_REVISIONI.IMPRONTA, DM_REVISIONI.CSTRING, DM_REVISIONI.COMPRESSIONMODE, DM_REVISIONI.PSWZIP, ");
                sb.Append("DM_PROFILE.AOO ");
                sb.Append("FROM DM_REVISIONI, DM_PROFILE ");
                sb.Append("WHERE DM_PROFILE.DOCNUMBER = DM_REVISIONI.NumDoc AND DM_REVISIONI.CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmRevisioniItem = new dmRevisioni()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["ID"]),
                                docNumber = System.Convert.ToInt32(reader["NumDoc"]),
                                storeDate = System.Convert.ToDateTime(reader["DataProf"]),
                                fileName = reader["NomeFile"].ToString(),
                                originale = reader["ORIGINALE"].ToString(),
                                revisione = System.Convert.ToInt32(reader["REVISIONE"]),
                                impronta = reader["IMPRONTA"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString()
                            };

                            dmRevisioni.Add(_dmRevisioniItem);
                        }
                    }
                }



                return dmRevisioni;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Update - DM_REVISIONI

        public void UpdateDM_REVISIONI(int ID, string path)
        {
            try
            {
                checkDBConnection(_dbConnection);

                StringBuilder sb = new StringBuilder();

                sb.Append("UPDATE DM_REVISIONI ");
                sb.Append("SET Percorso = @path, CSTRING = '' ");
                sb.Append("WHERE ID = @ID ");
                String sqlQuery = sb.ToString();

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                var docNumberParameter = command.CreateParameter();
                docNumberParameter.ParameterName = "@ID";
                docNumberParameter.Value = ID;

                command.Parameters.Add(docNumberParameter);

                var pathParameter = command.CreateParameter();
                pathParameter.ParameterName = "@path";
                pathParameter.Value = path;

                command.Parameters.Add(pathParameter);

                DbTransaction transaction = _dbConnection.BeginTransaction();
                command.Transaction = transaction;

                try
                {
                    command.ExecuteNonQuery();
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw (new Exception("Errore in transazione: " + ex.Message));
                }



            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        #endregion

        #region Load - DM_ALLEGATI_DOC
        public List<dmAllegatiDoc> loadDM_ALLEGATIDOC()
        {
            try
            {

                List<dmAllegatiDoc> dmAllegatiDoc = new List<dmAllegatiDoc>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT DM_ALLEGATIDOC.ID, DM_ALLEGATIDOC.DOCNUMBER, DM_ALLEGATIDOC.DATAIMPORT, DM_ALLEGATIDOC.NOMEFILE, DM_ALLEGATIDOC.NOMEORIGINALE, DM_ALLEGATIDOC.REVISIONE, DM_ALLEGATIDOC.IMPRONTA, DM_ALLEGATIDOC.CSTRING, DM_ALLEGATIDOC.COMPRESSIONMODE, ");
                sb.Append("DM_PROFILE.AOO, DM_ALLEGATIDOC.PSWZIP ");
                sb.Append("FROM DM_ALLEGATIDOC, DM_PROFILE ");
                sb.Append("WHERE DM_PROFILE.DOCNUMBER = DM_ALLEGATIDOC.DOCNUMBER AND DM_ALLEGATIDOC.CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmAllegatiDocItem = new dmAllegatiDoc()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["ID"]),
                                docNumber = System.Convert.ToInt32(reader["DOCNUMBER"]),
                                storeDate = System.Convert.ToDateTime(reader["DATAIMPORT"]),
                                fileName = reader["NOMEFILE"].ToString(),
                                originale = reader["NOMEORIGINALE"].ToString(),
                                revisione = System.Convert.ToInt32(reader["REVISIONE"]),
                                impronta = reader["IMPRONTA"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString()
                            };

                            dmAllegatiDoc.Add(_dmAllegatiDocItem);
                        }
                    }
                }



                return dmAllegatiDoc;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_ALLEGATI_DOC_REV
        public List<dmAllegatiDocRev> loadDM_ALLEGATIDOC_REV()
        {
            try
            {

                List<dmAllegatiDocRev> dmAllegatiDocRev = new List<dmAllegatiDocRev>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT DM_ALLEGATIDOC_REV.ID, DM_ALLEGATIDOC_REV.DMALLEGATIDOCID, DM_ALLEGATIDOC_REV.DATAIMPORT, DM_ALLEGATIDOC_REV.FILENAME, DM_ALLEGATIDOC_REV.ORIGINALE, DM_ALLEGATIDOC_REV.REVISIONE, DM_ALLEGATIDOC_REV.IMPRONTA, DM_ALLEGATIDOC_REV.CSTRING, DM_ALLEGATIDOC_REV.COMPRESSIONMODE, ");
                sb.Append("DM_PROFILE.AOO, DM_ALLEGATIDOC_REV.PSWZIP ");
                sb.Append("FROM DM_ALLEGATIDOC_REV, DM_ALLEGATIDOC, DM_PROFILE ");
                sb.Append("WHERE DM_PROFILE.DOCNUMBER = DM_ALLEGATIDOC.DOCNUMBER AND DM_ALLEGATIDOC.ID = DM_ALLEGATIDOC_REV.ID AND DM_ALLEGATIDOC_REV.CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmAllegatiDocRevItem = new dmAllegatiDocRev()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["ID"]),
                                allegatiDocId = System.Convert.ToInt32(reader["DMALLEGATIDOCID"]),
                                storeDate = System.Convert.ToDateTime(reader["DATAIMPORT"]),
                                fileName = reader["FILENAME"].ToString(),
                                originale = reader["ORIGINALE"].ToString(),
                                revisione = System.Convert.ToInt32(reader["REVISIONE"]),
                                impronta = reader["IMPRONTA"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString()
                            };

                            dmAllegatiDocRev.Add(_dmAllegatiDocRevItem);
                        }
                    }
                }



                return dmAllegatiDocRev;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_THUMBNAIL
        public List<dmThumbnail> loadDM_THUMBNAIL()
        {
            try
            {

                List<dmThumbnail> dmThumbnail = new List<dmThumbnail>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT DM_THUMBNAIL.ID, DM_THUMBNAIL.KEYID, DM_THUMBNAIL.KEYREVISION, DM_THUMBNAIL.PAGEINDEX, DM_THUMBNAIL.CREATION_DATE, DM_THUMBNAIL.FILENAME, DM_THUMBNAIL.ORIGINALE, DM_THUMBNAIL.IMPRONTA, DM_THUMBNAIL.CSTRING, DM_THUMBNAIL.COMPRESSIONMODE, ");
                sb.Append("DM_PROFILE.AOO, DM_THUMBNAIL.PSWZIP ");
                sb.Append("FROM DM_THUMBNAIL, DM_PROFILE ");
                sb.Append("WHERE DM_PROFILE.DOCNUMBER = DM_THUMBNAIL.KEYID AND DM_THUMBNAIL.CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmThumbnailItem = new dmThumbnail()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["ID"]),
                                docNumber = System.Convert.ToInt32(reader["KEYID"]),
                                pageIndex = System.Convert.ToInt32(reader["PAGEINDEX"]),
                                storeDate = System.Convert.ToDateTime(reader["CREATION_DATE"]),
                                fileName = reader["FILENAME"].ToString(),
                                originale = reader["ORIGINALE"].ToString(),
                                revisione = System.Convert.ToInt32(reader["KEYREVISION"]),
                                impronta = reader["IMPRONTA"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString()
                            };

                            dmThumbnail.Add(_dmThumbnailItem);
                        }
                    }
                }



                return dmThumbnail;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_MODULIOFFICE
        public List<dmModuliOffice> loadDM_MODULIOFFICE()
        {
            try
            {

                List<dmModuliOffice> dmModuliOffice = new List<dmModuliOffice>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT ID, Path, NomeFile, Originale, CSTRING, PATHPREVIEW, NOMEFILEPREVIEW, ORIGINALEPREVIEW, CSTRINGPREVIEW, COMPRESSIONMODE, COMPMODEPREVIEW, AOO, PSWZIP, PSWZIPPREVIEW ");
                sb.Append("FROM DM_MODULIOFFICE ");
                sb.Append("WHERE CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmModuliOfficeItem = new dmModuliOffice()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["ID"]),
                                path = reader["Path"].ToString(),
                                fileName = reader["NomeFile"].ToString(),
                                originale = reader["Originale"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                fileNamePreview = reader["NOMEFILEPREVIEW"].ToString(),
                                originalePreview = reader["ORIGINALEPREVIEW"].ToString(),
                                cstringPreview = reader["CSTRINGPREVIEW"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                compressionModePreview = System.Convert.ToInt32(reader["COMPMODEPREVIEW"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString(),
                                pswzipPreview = reader["PSWZIPPREVIEW"].ToString()
                            };

                            dmModuliOffice.Add(_dmModuliOfficeItem);
                        }
                    }
                }

                return dmModuliOffice;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_MSG
        public List<dmMsg> loadDM_MSG()
        {
            try
            {

                List<dmMsg> dmMsg = new List<dmMsg>();

                StringBuilder sb = new StringBuilder();

                /*
                 *select B.AOO,A.* from DM_MSG A
inner join DM_UTENTI B
on A.A=B.Email
where (A.ID_MITT is null or A.ID_MITT=0)
union all
select B.AOO,A.* from DM_MSG A
inner join DM_UTENTI B
on A.ID_MITT=B.UTENTE
where (A.ID_MITT is not null and A.ID_MITT<>0)

                             sb.Append("SELECT DM_MSG.ID, DM_MSG.DATA, DM_MSG.FILENAME, DM_MSG.CSTRING, DM_MSG.COMPRESSIONMODE, DM_UTENTI.AOO AS AOO ");
                sb.Append("FROM DM_MSG INNER JOIN DM_UTENTI ON DM_MSG.ID_MITT = DM_UTENTI.Utente ");
                sb.Append("WHERE (DM_MSG.ID_MITT IS NOT NULL AND DM_MSG.ID_MITT <> 0 AND DM_MSG.CSTRING <> '' )");
                sb.Append("UNION ");
                sb.Append("SELECT DM_MSG.ID, DM_MSG.DATA, DM_MSG.FILENAME, DM_MSG.CSTRING, DM_MSG.COMPRESSIONMODE, DM_UTENTI.AOO AS AOO ");
                sb.Append("FROM DM_MSG INNER JOIN DM_UTENTI ON DM_MSG.A = DM_UTENTI.Email WHERE (DM_MSG.ID_MITT IS NULL OR DM_MSG.ID_MITT = 0) AND  DM_MSG.CSTRING <> ''");

                 * */
                sb.Append("SELECT DM_MSG.ID, DM_MSG.DATA, DM_MSG.FILENAME, DM_MSG.CSTRING, DM_MSG.COMPRESSIONMODE, DM_UTENTI.AOO AS AOO, DM_MSG.PSWZIP ");
                sb.Append("FROM DM_MSG, DM_UTENTI ");
                sb.Append("WHERE DM_MSG.ID_MITT = DM_UTENTI.Utente AND DM_MSG.CSTRING <> '' ");
                sb.Append("UNION ");
                sb.Append("SELECT DM_MSG.ID, DM_MSG.DATA, DM_MSG.FILENAME, DM_MSG.CSTRING, DM_MSG.COMPRESSIONMODE, '' AS AOO, DM_MSG.PSWZIP ");
                sb.Append("FROM DM_MSG WHERE DM_MSG.CSTRING <> '' AND DM_MSG.ID_MITT IS NULL");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmMsgItem = new dmMsg()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["ID"]),
                                storeDate = System.Convert.ToDateTime(reader["DATA"]),
                                fileName = reader["FILENAME"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString()
                            };

                            dmMsg.Add(_dmMsgItem);
                        }
                    }
                }

                return dmMsg;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_MAILOUT
        public List<dmMailOut> loadDM_MAILOUT()
        {
            try
            {

                List<dmMailOut> dmMailOut = new List<dmMailOut>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT DM_MAILOUT.ID, DM_MAILOUT.ID_MSG, DM_MAILOUT.NOMEFILE, DM_MAILOUT.CSTRING, DM_MSG.DATA, DM_MAILOUT.COMPRESSIONMODE, DM_UTENTI.AOO, DM_MAILOUT.PSWZIP, DM_MAILOUT.STATO ");
                sb.Append("FROM DM_MAILOUT, DM_MSG, DM_UTENTI ");
                sb.Append("WHERE DM_MAILOUT.ID_MSG = DM_MSG.ID AND DM_MSG.ID_MITT = DM_UTENTI.Utente AND DM_MAILOUT.CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmMailOutItem = new dmMailOut()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["ID"]),
                                ID_MSG = System.Convert.ToInt32(reader["ID_MSG"]),
                                storeDate = System.Convert.ToDateTime(reader["DATA"]),
                                fileName = reader["NOMEFILE"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString(),
                                stato = System.Convert.ToInt32(reader["STATO"]),
                            };

                            dmMailOut.Add(_dmMailOutItem);
                        }
                    }
                }

                return dmMailOut;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_WORKFLOW
        public List<dmWorkflow> loadDM_WORKFLOW()
        {
            try
            {

                List<dmWorkflow> dmWorkflow = new List<dmWorkflow>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT ID, LASTEDIT_DATE, FILEFLW, CSTRING, COMPRESSIONMODE, AOO, PSWZIP ");
                sb.Append("FROM DM_WORKFLOW ");
                sb.Append("WHERE CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmWorkflowItem = new dmWorkflow()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["ID"]),
                                storeDate = System.Convert.ToDateTime(reader["LASTEDIT_DATE"]),
                                fileName = reader["FILEFLW"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString()
                            };

                            dmWorkflow.Add(_dmWorkflowItem);
                        }
                    }
                }

                return dmWorkflow;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_WORKFLOWPREVIEW
        public List<dmWorkflowPreview> loadDM_WORKFLOWPREVIEW()
        {
            try
            {

                List<dmWorkflowPreview> dmWorkflowPreview = new List<dmWorkflowPreview>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT DM_WORKFLOW_PREVIEW.DMWORKFLOWID, DM_WORKFLOW_PREVIEW.FILEPREVIEW, DM_WORKFLOW_PREVIEW.CSTRING, DM_WORKFLOW.LASTEDIT_DATE, DM_WORKFLOW_PREVIEW.COMPRESSIONMODE, DM_WORKFLOW.AOO, DM_WORKFLOW_PREVIEW.PSWZIP ");
                sb.Append("FROM DM_WORKFLOW, DM_WORKFLOW_PREVIEW ");
                sb.Append("WHERE DM_WORKFLOW.ID = DM_WORKFLOW_PREVIEW.DMWORKFLOWID AND DM_WORKFLOW_PREVIEW.CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmWorkflowPreviewItem = new dmWorkflowPreview()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["DMWORKFLOWID"]),
                                storeDate = System.Convert.ToDateTime(reader["LASTEDIT_DATE"]),
                                filePreview = reader["FILEPREVIEW"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString()
                            };

                            dmWorkflowPreview.Add(_dmWorkflowPreviewItem);
                        }
                    }
                }

                return dmWorkflowPreview;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_PROCESSI
        public List<dmProcessi> loadDM_PROCESSI()
        {
            try
            {

                List<dmProcessi> dmProcessi = new List<dmProcessi>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT ID, INIZIO, FILEFLW, CSTRING, COMPRESSIONMODE, AOO, PSWZIP ");
                sb.Append("FROM DM_PROCESSI ");
                sb.Append("WHERE CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmProcessiItem = new dmProcessi()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["ID"]),
                                storeDate = System.Convert.ToDateTime(reader["INIZIO"]),
                                fileName = reader["FILEFLW"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString()
                            };

                            dmProcessi.Add(_dmProcessiItem);
                        }
                    }
                }

                return dmProcessi;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_PROCESSDOC
        public List<dmProcessDoc> loadDM_PROCESSDOC()
        {
            try
            {

                List<dmProcessDoc> dmProcessDoc = new List<dmProcessDoc>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT DM_PROCESSDOC.ID, DM_PROCESSDOC.REV, DM_PROCESSDOC.NOMEFILE, DM_PROCESSDOC.DATA, DM_PROCESSDOC.CSTRING, DM_PROCESSDOC.COMPRESSIONMODE, DM_PROCESSI.AOO, DM_PROCESSDOC.PSWZIP ");
                sb.Append("FROM DM_PROCESSDOC, DM_PROCESSI ");
                sb.Append("WHERE DM_PROCESSDOC.IDPROCESSO = DM_PROCESSI.ID AND DM_PROCESSDOC.CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmProcessDocItem = new dmProcessDoc()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["ID"]),
                                storeDate = System.Convert.ToDateTime(reader["DATA"]),
                                revisione = System.Convert.ToInt32(reader["REV"]),
                                fileName = reader["NOMEFILE"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString()
                            };

                            dmProcessDoc.Add(_dmProcessDocItem);
                        }
                    }
                }

                return dmProcessDoc;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_PROCESSDOC_CLOSE
        public List<dmProcessDoc> loadDM_PROCESSDOC_CLOSE()
        {
            try
            {

                List<dmProcessDoc> dmProcessDocClose = new List<dmProcessDoc>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT DM_PROCESSDOC_CLOSE.ID, DM_PROCESSDOC_CLOSE.REV, DM_PROCESSDOC_CLOSE.NOMEFILE, DM_PROCESSDOC_CLOSE.DATA, DM_PROCESSDOC_CLOSE.CSTRING, DM_PROCESSDOC_CLOSE.COMPRESSIONMODE, DM_PROCESSI.AOO, DM_PROCESSDOC_CLOSE.PSWZIP ");
                sb.Append("FROM DM_PROCESSDOC_CLOSE, DM_PROCESSI ");
                sb.Append("WHERE DM_PROCESSDOC_CLOSE.IDPROCESSO = DM_PROCESSI.ID AND DM_PROCESSDOC_CLOSE.CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmProcessDocCloseItem = new dmProcessDoc()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["ID"]),
                                storeDate = System.Convert.ToDateTime(reader["DATA"]),
                                revisione = System.Convert.ToInt32(reader["REV"]),
                                fileName = reader["NOMEFILE"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString()
                            };

                            dmProcessDocClose.Add(_dmProcessDocCloseItem);
                        }
                    }
                }

                return dmProcessDocClose;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_ALLEGATIWORK
        public List<dmAllegatiWork> loadDM_ALLEGATIWORK()
        {
            try
            {

                List<dmAllegatiWork> dmAllegatiWork = new List<dmAllegatiWork>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT DM_ALLEGATIWORK.ID, DM_ALLEGATIWORK.NomeInterno, DM_ALLEGATIWORK.Data, DM_ALLEGATIWORK.CSTRING, DM_ALLEGATIWORK.COMPRESSIONMODE, DM_WORKFLOW.AOO, DM_ALLEGATIWORK.PSWZIP ");
                sb.Append("FROM DM_ALLEGATIWORK, DM_WORKFLOW ");
                sb.Append("WHERE DM_ALLEGATIWORK.IDWorkflow = DM_WORKFLOW.ID AND DM_ALLEGATIWORK.CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmAllegatiWorkItem = new dmAllegatiWork()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["ID"]),
                                storeDate = System.Convert.ToDateTime(reader["Data"]),
                                fileName = reader["NomeInterno"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString()
                            };

                            dmAllegatiWork.Add(_dmAllegatiWorkItem);
                        }
                    }
                }

                return dmAllegatiWork;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_ALLEGATIWORK_CLOSE
        public List<dmAllegatiWork> loadDM_ALLEGATIWORK_CLOSE()
        {
            try
            {

                List<dmAllegatiWork> dmAllegatiWorkClose = new List<dmAllegatiWork>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT DM_ALLEGATIWORK_CLOSE.ID, DM_ALLEGATIWORK_CLOSE.NomeInterno, DM_ALLEGATIWORK_CLOSE.Data, DM_ALLEGATIWORK_CLOSE.CSTRING, DM_ALLEGATIWORK_CLOSE.COMPRESSIONMODE, DM_WORKFLOW.AOO, DM_ALLEGATIWORK_CLOSE.PSWZIP ");
                sb.Append("FROM DM_ALLEGATIWORK_CLOSE, DM_WORKFLOW, DM_PROCESSI ");
                sb.Append("WHERE DM_ALLEGATIWORK_CLOSE.IDWorkflow = DM_PROCESSI.ID AND DM_PROCESSI.WORKFLOW = DM_WORKFLOW.ID AND DM_ALLEGATIWORK_CLOSE.CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmAllegatiWorkCloseItem = new dmAllegatiWork()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["ID"]),
                                storeDate = System.Convert.ToDateTime(reader["Data"]),
                                fileName = reader["NomeInterno"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString()
                            };

                            dmAllegatiWorkClose.Add(_dmAllegatiWorkCloseItem);
                        }
                    }
                }

                return dmAllegatiWorkClose;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_PLUGINCUSTOM
        public List<dmPluginCustom> loadDM_PLUGINCUSTOM()
        {
            try
            {

                List<dmPluginCustom> dmPluginCustom = new List<dmPluginCustom>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT DM_PLUGINCUSTOM.ID, DM_PLUGINCUSTOM.FILEZIPNAME, DM_PLUGINCUSTOM.DATACARICAMENTO, DM_PLUGINCUSTOM.HASHMD5, DM_PLUGINCUSTOM.CSTRING, DM_PLUGINCUSTOM.COMPRESSIONMODE, DM_UTENTI.AOO, DM_PLUGINCUSTOM.PSWZIP ");
                sb.Append("FROM DM_PLUGINCUSTOM, DM_UTENTI ");
                sb.Append("WHERE DM_PLUGINCUSTOM.DMUTENTIID = DM_UTENTI.Utente AND DM_PLUGINCUSTOM.CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmPluginCustomItem = new dmPluginCustom()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = System.Convert.ToInt32(reader["ID"]),
                                storeDate = System.Convert.ToDateTime(reader["DATACARICAMENTO"]),
                                impronta = reader["HASHMD5"].ToString(),
                                fileName = reader["FILEZIPNAME"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString()
                            };

                            dmPluginCustom.Add(_dmPluginCustomItem);
                        }
                    }
                }

                return dmPluginCustom;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_BUFFER
        public List<dmBuffer> loadDM_BUFFER()
        {
            try
            {

                List<dmBuffer> dmBuffer = new List<dmBuffer>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT DM_BUFFER.ID, DM_BUFFER.FILENAME, DM_BUFFER.CREATIONDATE, DM_BUFFER.HASH, DM_BUFFER.CSTRING, DM_BUFFER.COMPRESSIONMODE, DM_UTENTI.AOO, DM_BUFFER.PSWZIP ");
                sb.Append("FROM DM_BUFFER, DM_UTENTI ");
                sb.Append("WHERE DM_UTENTI.Utente = DM_BUFFER.AUTORE AND DM_BUFFER.CSTRING <> ''");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmBufferItem = new dmBuffer()
                            {
                                 _id = MongoDB.Bson.ObjectId.GenerateNewId(),
                                ID = reader["ID"].ToString(),
                                storeDate = System.Convert.ToDateTime(reader["CREATIONDATE"]),
                                impronta = reader["HASH"].ToString(),
                                fileName = reader["FILENAME"].ToString(),
                                cstring = reader["CSTRING"].ToString(),
                                compressionMode = System.Convert.ToInt32(reader["COMPRESSIONMODE"]),
                                aoo = reader["AOO"].ToString(),
                                pswzip = reader["PSWZIP"].ToString()
                            };

                            dmBuffer.Add(_dmBufferItem);
                        }
                    }
                }

                return dmBuffer;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Load - DM_AOO
        public List<dmAoo> loadDM_AOO()
        {
            try
            {

                List<dmAoo> dmAoo = new List<dmAoo>();

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT * FROM DM_AOO");

                DbCommand command = _dbConnection.CreateCommand();
                command.CommandText = sb.ToString();
                command.CommandType = CommandType.Text;

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var _dmAooItem = new dmAoo()
                            {
                                codice = reader["CODICE"].ToString(),
                                denominazione = reader["DENOMINAZIONE"].ToString(),
                                pathEdit = reader["PATHEDIT"].ToString(),
                                pathFile = reader["PATHFILE"].ToString(),
                                pathLog = reader["PATHLOG"].ToString(),
                                pathMail = reader["PATHMAIL"].ToString(),
                                saveType = System.Convert.ToInt32(reader["SAVETYPE"])
                            };

                            dmAoo.Add(_dmAooItem);
                        }
                    }
                }

                return dmAoo;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region LOAD
        public List<dynamic> Load(Type type)
        {
            try
            {

                List<dynamic> obj = new List<dynamic>();
                checkDBConnection(_dbConnection);
                switch (type.Name)
                {

                    case "dmProfile":
                        obj = loadDM_PROFILE().Cast<dynamic>().ToList();
                        break;
                    case "dmRevisioni":
                        obj = loadDM_REVISIONI().Cast<dynamic>().ToList();
                        break;
                    case "dmAllegatiDoc":
                        obj = loadDM_ALLEGATIDOC().Cast<dynamic>().ToList();
                        break;
                    case "dmAllegatiDocRev":
                        obj = loadDM_ALLEGATIDOC_REV().Cast<dynamic>().ToList();
                        break;
                    case "dmThumbnail":
                        obj = loadDM_THUMBNAIL().Cast<dynamic>().ToList();
                        break;
                    case "dmModuliOffice":
                        obj = loadDM_MODULIOFFICE().Cast<dynamic>().ToList();
                        break;
                    case "dmMsg":
                        obj = loadDM_MSG().Cast<dynamic>().ToList();
                        break;
                    case "dmMailOut":
                        obj = loadDM_MAILOUT().Cast<dynamic>().ToList();
                        break;
                    case "dmWorkflow":
                        obj = loadDM_WORKFLOW().Cast<dynamic>().ToList();
                        break;
                    case "dmWorkflowPreview":
                        obj = loadDM_WORKFLOWPREVIEW().Cast<dynamic>().ToList();
                        break;
                    case "dmProcessi":
                        obj = loadDM_PROCESSI().Cast<dynamic>().ToList();
                        break;
                    case "dmProcessDoc":
                        obj = loadDM_PROCESSDOC().Cast<dynamic>().ToList();
                        break;
                    case "dmProcessDocClose":
                        obj = loadDM_PROCESSDOC_CLOSE().Cast<dynamic>().ToList();
                        break;
                    case "dmAllegatiWork":
                        obj = loadDM_ALLEGATIWORK().Cast<dynamic>().ToList();
                        break;
                    case "dmAllegatiWorkClose":
                        obj = loadDM_ALLEGATIWORK_CLOSE().Cast<dynamic>().ToList();
                        break;
                    case "dmPluginCustom":
                        obj = loadDM_PLUGINCUSTOM().Cast<dynamic>().ToList();
                        break;
                    case "dmBuffer":
                        obj = loadDM_BUFFER().Cast<dynamic>().ToList();
                        break;
                }
                return obj;
            }
            catch(Exception ex)
            {

                throw (ex);
            }
        }
        #endregion
      
        #region UPDATE
        public void Update(Type type, int ID, string path, string pathPreview)
        {
            try
            {
                if (!this._config.TestMode)
                {

                    checkDBConnection(_dbConnection);

                    string updateQuery = "";

                    switch (type.Name)
                    {
                        case "dmProfile":
                            updateQuery = "UPDATE DM_PROFILE SET PATH = @path, CSTRING = '' WHERE DOCNUMBER = @ID";
                            break;
                        case "dmRevisioni":
                            updateQuery = "UPDATE DM_REVISIONI SET Percorso = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmAllegatiDoc":
                            updateQuery = "UPDATE DM_ALLEGATIDOC SET PATHFILE = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmAllegatiDocRev":
                            updateQuery = "UPDATE DM_ALLEGATIDOC_REV SET PATHFILE = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmThumbnail":
                            updateQuery = "UPDATE DM_THUMBNAIL SET PATH = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmModuliOffice":
                            updateQuery = "UPDATE DM_MODULIOFFICE SET Path = @path, PathPreview = @pathPreview, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmMsg":
                            updateQuery = "UPDATE DM_MSG SET PATHFILE = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmMailOut":
                            updateQuery = "UPDATE DM_MAILOUT SET PATH = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmWorkflow":
                            updateQuery = "UPDATE DM_WORKFLOW SET PERCORSO = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmWorkflowPreview":
                            updateQuery = "UPDATE DM_WORKFLOW_PREVIEW SET PATHFILE = @path, CSTRING = '' WHERE DMWORKFLOWID = @ID";
                            break;
                        case "dmProcessi":
                            updateQuery = "UPDATE DM_PROCESSI SET PATH = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmProcessDoc":
                            updateQuery = "UPDATE DM_PROCESSDOC SET PATH = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmProcessDocClose":
                            updateQuery = "UPDATE DM_PROCESSDOC_CLOSE SET PATH = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmAllegatiWork":
                            updateQuery = "UPDATE DM_ALLEGATIWORK SET Percorso = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmAllegatiWorkClose":
                            updateQuery = "UPDATE DM_ALLEGATIWORK_CLOSE SET Percorso = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmPluginCustom":
                            updateQuery = "UPDATE DM_PLUGINCUSTOM SET PATH = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmBuffer":
                            updateQuery = "UPDATE DM_BUFFER SET PATH = @path, CSTRING = '' WHERE ID = @ID";
                            break;

                    }


                    StringBuilder sb = new StringBuilder();


                    sb.Append(updateQuery);

                    String sqlQuery = sb.ToString();

                    DbCommand command = _dbConnection.CreateCommand();
                    command.CommandText = sb.ToString();
                    command.CommandType = CommandType.Text;

                    var docNumberParameter = command.CreateParameter();
                    docNumberParameter.ParameterName = "@ID";
                    docNumberParameter.Value = ID;

                    command.Parameters.Add(docNumberParameter);

                    var pathParameter = command.CreateParameter();
                    pathParameter.ParameterName = "@path";
                    pathParameter.Value = path;

                    command.Parameters.Add(pathParameter);

                    var pathPreviewParameter = command.CreateParameter();
                    pathPreviewParameter.ParameterName = "@pathPreview";
                    pathPreviewParameter.Value = pathPreview;

                    command.Parameters.Add(pathPreviewParameter);

                    DbTransaction transaction = _dbConnection.BeginTransaction();
                    command.Transaction = transaction;

                    try
                    {
                        command.ExecuteNonQuery();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw (new Exception("Errore in transazione" + ex.Message));
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }

        }

        public void Update(Type type, string ID, string path, string pathPreview)
        {
            try
            {
                if(!this._config.TestMode)
                {
                    checkDBConnection(_dbConnection);

                    string updateQuery = "";

                    switch (type.Name)
                    {
                        case "dmProfile":
                            updateQuery = "UPDATE DM_PROFILE SET PATH = @path, CSTRING = '' WHERE DOCNUMBER = @ID";
                            break;
                        case "dmRevisioni":
                            updateQuery = "UPDATE DM_REVISIONI SET Percorso = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmAllegatiDoc":
                            updateQuery = "UPDATE DM_ALLEGATI_DOC SET PATHFILE = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmAllegatiDocRev":
                            updateQuery = "UPDATE DM_ALLEGATI_DOC_REV SET PATHFILE = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmThumbnail":
                            updateQuery = "UPDATE DM_THUMBNAIL SET PATH = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmModuliOffice":
                            updateQuery = "UPDATE DM_MODULIOFFICE SET Path = @path, PathPreview = @pathPreview, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmMsg":
                            updateQuery = "UPDATE DM_MSG SET PATHFILE = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmMailOut":
                            updateQuery = "UPDATE DM_MAILOUT SET PATH = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmWorkflow":
                            updateQuery = "UPDATE DM_WORKFLOW SET PERCORSO = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmWorkflowPreview":
                            updateQuery = "UPDATE DM_WORKFLOW_PREVIEW SET PATHFILE = @path, CSTRING = '' WHERE DMWORKFLOWID = @ID";
                            break;
                        case "dmProcessi":
                            updateQuery = "UPDATE DM_PROCESSI SET PATH = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmProcessDoc":
                            updateQuery = "UPDATE DM_PROCESSDOC SET PATH = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmProcessDocClose":
                            updateQuery = "UPDATE DM_PROCESSDOC_CLOSE SET PATH = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmAllegatiWork":
                            updateQuery = "UPDATE DM_ALLEGATIWORK SET Percorso = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmAllegatiWorkClose":
                            updateQuery = "UPDATE DM_ALLEGATIWORK_CLOSE SET Percorso = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmPluginCustom":
                            updateQuery = "UPDATE DM_PLUGINCUSTOM SET PATH = @path, CSTRING = '' WHERE ID = @ID";
                            break;
                        case "dmBuffer":
                            updateQuery = "UPDATE DM_BUFFER SET PATH = @path, CSTRING = '' WHERE ID = @ID";
                            break;

                    }


                    StringBuilder sb = new StringBuilder();


                    sb.Append(updateQuery);

                    String sqlQuery = sb.ToString();

                    DbCommand command = _dbConnection.CreateCommand();
                    command.CommandText = sb.ToString();
                    command.CommandType = CommandType.Text;

                    var docNumberParameter = command.CreateParameter();
                    docNumberParameter.ParameterName = "@ID";
                    docNumberParameter.Value = ID;

                    command.Parameters.Add(docNumberParameter);

                    var pathParameter = command.CreateParameter();
                    pathParameter.ParameterName = "@path";
                    pathParameter.Value = path;

                    command.Parameters.Add(pathParameter);

                    var pathPreviewParameter = command.CreateParameter();
                    pathPreviewParameter.ParameterName = "@pathPreview";
                    pathPreviewParameter.Value = pathPreview;

                    command.Parameters.Add(pathPreviewParameter);

                    DbTransaction transaction = _dbConnection.BeginTransaction();
                    command.Transaction = transaction;

                    try
                    {
                        command.ExecuteNonQuery();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw (new Exception("Errore in transazione" + ex.Message));
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }

        }
        #endregion

        #region Insert DM_THUMBNAIL_QUEUE
        public void InsertDmThumbnailQueue(string ID, string KEYID, string KEYREVISION, string DMCOUNTERSTABLES)
        {
            try
            {
                if (!this._config.TestMode)
                {

                    checkDBConnection(_dbConnection);

                    StringBuilder sb = new StringBuilder();

                    sb.Append("INSERT INTO DM_THUMBNAIL_QUEUE (ID, KEYID, KEYREVISION, DMCOUNTERSTABLES, STATUS, ATTEMPTDATE, ATTEMPTNUMBER, ERRORMESSAGE)");
                    sb.Append(" VALUES (@ID, @KEYID, @KEYREVISION, @DMCOUNTERSTABLES, 0, NULL, 0, NULL)");
                    String sqlQuery = sb.ToString();

                    DbCommand command = _dbConnection.CreateCommand();
                    command.CommandText = sb.ToString();
                    command.CommandType = CommandType.Text;

                    var keyID = command.CreateParameter();
                    keyID.ParameterName = "@ID";
                    keyID.Value = ID;

                    command.Parameters.Add(keyID);

                    var keyIDParameter = command.CreateParameter();
                    keyIDParameter.ParameterName = "@KEYID";
                    keyIDParameter.Value = KEYID;

                    command.Parameters.Add(keyIDParameter);

                    var keyRevisionParameter = command.CreateParameter();
                    keyRevisionParameter.ParameterName = "@KEYREVISION";
                    keyRevisionParameter.Value = KEYREVISION;

                    command.Parameters.Add(keyRevisionParameter);

                    var dmCounterTablesParameter = command.CreateParameter();
                    dmCounterTablesParameter.ParameterName = "@DMCOUNTERSTABLES";
                    dmCounterTablesParameter.Value = DMCOUNTERSTABLES;

                    command.Parameters.Add(dmCounterTablesParameter);

                    DbTransaction transaction = _dbConnection.BeginTransaction();
                    command.Transaction = transaction;

                    try
                    {
                        command.ExecuteNonQuery();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw (new Exception("Errore in transazione" + ex.Message));
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }

        }
        #endregion

        #region Load - DM_FILES
        public Arx_File extractFile(string fileName, string connectionString, string path, int compressionMode, Abletech.Arxivar.Entities.Enums.DbFiles_Table dbTable, string pswzip)
        {
            try
            {

                Arx_File documentoCompresso = (Arx_File)null;
                Arx_File file = (Arx_File)null;
                string NomeFile_Estratto = "";

                bool flag = (uint)compressionMode > 0U;
                Abletech.Arxivar.Server.Dal.BaseDal xbaseDalx;

                xbaseDalx = Abletech.Arxivar.Server.Dal.BaseDal.CreateObjectFromConnectionString(connectionString, false);

                documentoCompresso = Abletech.Arxivar.Server.Dal.Common.GetCompressedDocumentFromDb(connectionString, fileName, dbTable, Path.GetTempPath(), false);
                if(documentoCompresso == null)
                {
                    
                    documentoCompresso = Abletech.Arxivar.Server.Dal.Common.GetCompressedDocumentFromDb(connectionString, fileName, dbTable, Path.GetTempPath(), true);
                }
                if (documentoCompresso != null)
                {

                    Abletech.Arxivar.Server.Dal.Common.SaveDocumentToFileSystem(Path.GetDirectoryName(path), Path.GetFileName(path), true, documentoCompresso);

                    if (flag)
                    {
                        file = EstractDocument(documentoCompresso, pswzip, (Abletech.Arxivar.Entities.Enums.ArxCompressionMode)Abletech.Arxivar.Server.Dal.Common.GetNumInt(compressionMode), out NomeFile_Estratto, Path.GetTempPath());
                    }
                    else if (documentoCompresso != null)
                        file = documentoCompresso;

                    return file;

                }
                else
                    return null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        
        #region Delete - DM_FILES
        public void deleteFile(string fileName, string connectionString, string path, int compressionMode, Abletech.Arxivar.Entities.Enums.DbFiles_Table dbTable)
        {
            try
            {

                Abletech.Arxivar.Server.Dal.Common.DeleteDocument(fileName,connectionString, dbTable, Path.GetTempPath(), false);
    
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        public static Arx_File EstractDocument(Arx_File documentoCompresso,string encryptedPasswordZip,Abletech.Arxivar.Entities.Enums.ArxCompressionMode compressionMode,out string nomeFileContenutoNelloZip,string chunkingWorkingPath)
        {
            try
            {
                if (compressionMode == Abletech.Arxivar.Entities.Enums.ArxCompressionMode.None)
                    throw new ArgumentException("Compression not supported: " + (object)Abletech.Arxivar.Entities.Enums.ArxCompressionMode.None);
                if (!Directory.Exists(chunkingWorkingPath))
                    throw new DirectoryNotFoundException(chunkingWorkingPath);
                string str1 = Path.Combine(chunkingWorkingPath, "GET_DOC");
                if (!Directory.Exists(str1))
                    Directory.CreateDirectory(str1);
                string str2 = Path.Combine(str1, Guid.NewGuid().ToString());
                if (!Directory.Exists(str2))
                    Directory.CreateDirectory(str2);
                if (compressionMode == Abletech.Arxivar.Entities.Enums.ArxCompressionMode.CompressChilkat91)
                    ZipUnzipLegacy.EstractDocument(documentoCompresso.CurrentFile, str2, encryptedPasswordZip, out nomeFileContenutoNelloZip, str2);
                else
                    ZipUnzip.EstractDocument(documentoCompresso.CurrentFile, str2, encryptedPasswordZip, out nomeFileContenutoNelloZip, str2);
                if (string.IsNullOrEmpty(nomeFileContenutoNelloZip))
                {
                    nomeFileContenutoNelloZip = string.Empty;
                    return (Arx_File)null;
                }
                string str3 = Path.Combine(str2, nomeFileContenutoNelloZip);
                if (!File.Exists(str3))
                {
                    nomeFileContenutoNelloZip = string.Empty;
                    return (Arx_File)null;
                }
                return new Arx_File(str3, str2)
                {
                    DeleteFolderOnDisposeIfEmpty = true
                };
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Abletech.Arxivar.Server.Dal.Common.EstractDocument_2: {0}", (object)ex.Message));
            }
        }
    }

}
"

Riusciresti a scrivermi il codice per farlo funzionare sia per sql sia per oracle?