示例#1
0
 public DalInvCrustedLeatherIssueFromStore()
 {
     _vmMsg      = new ValidationMsg();
     _unit       = new UnitOfWork();
     _context    = new BLC_DEVEntities();
     _connString = StrConnection.GetConnectionString();
 }
示例#2
0
        public AppConfigFile()
        {
            string appFullPath;

            App.GetAppFullPath(out appFullPath, out _, out _, removeExe: true);
            //if (appFullPath.Right(4).ToLower() == ".exe") appFullPath = appFullPath.Left(-4);
            appFullPath += ".cfg";

            this.FullFilePath = appFullPath;


            MainDbConnString    = new StrConnection();
            IsEncrypted         = false;
            this.configurations = new List <Configs.ConfigurazioneSuFile>(); //Lasciare il value di tipo object altrimenti il serializzatore dice che non riesce ad instanziare Configs poichè MustInherits
        }
示例#3
0
 public SqlObj(StrConnection connStr = null, OleDbCommand cmd = null, OleDbTransaction tra = null)
 {
     if (connStr != null)
     {
         this.connStr = connStr;
     }
     if (cmd != null)
     {
         this.cmd = cmd;
     }
     else
     {
         this.cmd = new OleDbCommand(); //Messo qui e non dentro ConnettiDB per riutilizzare lo stesso oggetto, ConnettiDB avrà sempre cmd inizializzato
     }
     this.tra = tra;
 }
示例#4
0
 public DAL()
 {
     builder = new SqlConnectionStringBuilder();
     string[] str = StrConnection.Split(',');
     builder.DataSource         = str[0];
     builder.UserID             = str[1];
     builder.Password           = str[2];
     builder.InitialCatalog     = "QuanLyThiTracNghiemOnline";
     builder.IntegratedSecurity = bool.Parse(str[3]);
     ERROR = "";
     try
     {
         conn = new SqlConnection(builder.ConnectionString);
         comm = conn.CreateCommand();
     }
     catch (Exception e) { ERROR = e.Message; }
 }
示例#5
0
        public bool ExecNoQuery(string query, CommitRoll commitRollback = CommitRoll.commitRollback, NuovaConn nuovaConn = NuovaConn.seNecessario, StrConnection strConn = null, Int32 timeOutQuery = 0, Mess logMess = null)
        {
            if (logMess == null)
            {
                logMess = new Mess(LogType.ERR, Log.main.errUserText);
            }
            logMess.testoDaLoggare = "";

            Thread thread; Exception thrEx = null; bool esito; string testoTmp;

            if (PreExec(true, query, ref strConn, nuovaConn, ref timeOutQuery, logMess) == false)
            {
                return(false);
            }

            esito  = false;
            thread = Thr.AvviaNuovo(() => esito = ThrENQ_Exec(out thrEx));

            if (Thr.AttesaCompletamento(ref thread, timeOutQuery) == false)
            { //qua non faccio rollback poichè presumo che la connessione remota sia andata persa, se DB in locale non può andare in timeout
                logMess.testoDaLoggare = "query:<" + cmd.CommandText + "> andata in timeOut:<" + timeOutQuery + ">";
                Log.main.Add(logMess);
                return(false);
            }

            if (esito == false)
            {
                try
                {
                    if (commitRollback == CommitRoll.commitRollback || commitRollback == CommitRoll.soloRollback)
                    {
                        tra.Rollback();
                        this.DisconnettiDB();
                    }
                }
                catch (Exception ex)
                {
                    logMess.testoDaVisual  = ""; //Non visualizzo nulla poichè c'è il l'altro log sotto
                    logMess.testoDaLoggare = "eccezione durante rollback, ex.Mess:<" + ex.Message + ">, query:<" + query + ">";
                    Log.main.Add(logMess);
                }

                if (thrEx != null)
                {
                    if (FiltraEccezioniQuery(thrEx) == true)
                    {
                        logMess.testoDaVisual = "";
                        logMess.tipo          = LogType.Warn;
                    }
                    testoTmp = "ex.mess:<" + thrEx.Message + ">";
                }
                else
                {
                    testoTmp = "il thread ThrENQ_Exec è ritornato false ma senza eccezioni";
                }


                logMess.testoDaLoggare = "query:<" + cmd.CommandText + ">, " + testoTmp;
                Log.main.Add(logMess);
                return(false);
            }

            try
            {
                if (commitRollback == CommitRoll.commitRollback)
                {
                    tra.Commit();
                    this.DisconnettiDB();
                }
            }
            catch (Exception ex)
            {
                if (FiltraEccezioniCommit(ex) == true)
                {
                    logMess.testoDaVisual = "";
                    logMess.tipo          = LogType.Warn;
                }

                logMess.testoDaLoggare = "errore durante 'sqlTra.Commit()', ex.Mess:<" + ex.Message + ">, query:<" + query + ">";
                Log.main.Add(logMess);
                return(false);
            }

            return(true);
        }
示例#6
0
        //ATTENZIONE res se non è un ref non funziona
        public bool ExecQuery <T1>(string query, ref T1 res, QryOut @out = QryOut.dataTable, NuovaConn nuovaConn = NuovaConn.seNecessario, StrConnection strConn = null, int timeOutQuery = 0, Mess logMess = null)
        {   //Attenzione: l'out come Datatable costa di più in termini di cpu, dataReader costa meno
            if (logMess == null)
            {
                logMess = new Mess(LogType.ERR, Log.main.errUserText);
            }
            logMess.testoDaLoggare = "";

            Thread thread; Exception thrEx = null; bool esito; string testoTmp;

            if (PreExec(true, query, ref strConn, nuovaConn, ref timeOutQuery, logMess) == false)
            {
                return(false);
            }

            if (res == null)
            {
                this.@out = @out;
            }
            else
            {
                if (res.GetType() == typeof(DataTable))
                {
                    this.@out = QryOut.dataTable;
                }
                else if (res.GetType() == typeof(OleDbDataReader))
                {
                    this.@out = QryOut.dataReader;
                }
                else
                {
                    logMess.testoDaLoggare = "ricevuto res con tipo disatteso, res.GetType.Name:<" + res.GetType().Name + ">";
                    Log.main.Add(logMess);
                    return(false);
                }
            }

            esito = false;
            //se si perde la connessione prima di eseguire cmd.ExecuteReader() (può succede per DB remoto quando si è già connessi, quindi con nuovaConn=False) passano 47 secondi prima che ritorna l'errore data provider interno 30,
            thread = Thr.AvviaNuovo(() => esito = ThrEQ_Exec(ref thrEx), ApartmentState.MTA); //Attenzione se STA, alla 'resOle.Close()' c'è l'eccezione: Impossibile utilizzare oggetti COM separati dai relativi RCW sottostanti.

            if (Thr.AttesaCompletamento(ref thread, timeOutQuery) == false)
            {
                logMess.testoDaLoggare = "query:<" + cmd.CommandText + "> andata in timeOut:<" + timeOutQuery + ">";
                Log.main.Add(logMess);
                return(false);
            }

            if (esito == false)
            {
                if (thrEx != null)
                {
                    if (FiltraEccezioniQuery(thrEx) == true)
                    {
                        logMess.testoDaVisual = "";
                        logMess.tipo          = LogType.Warn;
                    }
                    testoTmp = "ex.mess:<" + thrEx.Message + ">";
                }
                else
                {
                    testoTmp = "il thread ThrEQ_Exec è ritornato false ma senza eccezioni";
                }

                logMess.testoDaLoggare = "query:<" + cmd.CommandText + ">, " + testoTmp;
                Log.main.Add(logMess);
                return(false);
            }
            //Ho dovuto eseguire la resDt.Load(cmd.ExecuteReader()) nel delegato poichè se esegiuvo la resDt.Load(DataReader) qua da la seguente eccezione
            //Impossibile eseguire il cast di oggetti COM di tipo 'System.__ComObject' in tipi di interfaccia 'IRowset'. L'operazione non è stata completata perché la chiamata QueryInterface sul componente COM per l'interfaccia con IID '{ 0C733A7C - 2A1C - 11CE - ADE5 - 00AA0044773D}
            //non è riuscita a causa del seguente errore: Interfaccia non supportata. (Eccezione da HRESULT: 0x80004002 (E_NOINTERFACE)).

            if (res != null)
            {
                if (this.@out == QryOut.dataTable)
                {
                    res = (T1)(dynamic)ResDt;
                }
                else if (this.@out == QryOut.dataReader)
                {
                    res = (T1)(dynamic)ResOle;
                }
            }

            return(true);
        }
示例#7
0
        public bool ExecQuery(string query, QryOut @out = QryOut.dataTable, NuovaConn nuovaConn = NuovaConn.seNecessario, StrConnection strConn = null, int timeOutQuery = 0, Mess logMess = null)
        {
            object res = null;

            return(ExecQuery(query, ref res, @out: @out, nuovaConn: nuovaConn, strConn: strConn, timeOutQuery: timeOutQuery, logMess: logMess));
        }
示例#8
0
        private bool PreExec(bool isQuery, string query, ref StrConnection strConn, NuovaConn nuovaConn, ref Int32 timeOutQuery, Mess logMess)
        {
            if (strConn != null)
            {
                this.connStr = strConn;
            }
            if (this.connStr == null)
            {
                if (App.Db.ConnString != null)
                {
                    this.connStr = App.Db.ConnString;
                }
                else
                {
                    logMess.testoDaLoggare = "ricevuto strConn a nothing, Me.strConn è nothing e App.Db.ConnString è nothing, nessuna stringa di connessione disponibile";
                    Log.main.Add(new Mess(LogType.ERR, Log.main.errUserText, logMess.testoDaLoggare));  //Qui ci vuole sempre errore indipendentemente da tipoLog, per questo faccio un nuovo mess
                    return(false);
                }
            }

            if (this.connStr.IsInizializzata == false)
            {
                if (this.connStr.InizializzaSingoliCampi() == false)
                {
                    return(false);
                }
            }


            if (timeOutQuery == 0)
            { //se timeOutQuery=0 Carica timeout della config a meno che non sia locale (in questo caso attesa di tempo sempre infinita)
                if (this.connStr.DbRemoto == false)
                {
                    timeOutQuery = -1;
                }                      //Attesa di tempo infinita
                else if (isQuery == true)
                {
                    timeOutQuery = Sql.config.timeOutQuery;
                }
                else
                {
                    timeOutQuery = Sql.config.timeOutNonQuery;
                }
            }
            else if (timeOutQuery < -1)
            {
                logMess.testoDaLoggare = "ricevuto timeOutQuery inferiore a -1";
                Log.main.Add(new Mess(LogType.ERR, Log.main.errUserText, logMess.testoDaLoggare)); //Qui ci vuole sempre errore indipendentemente da tipoLog, per questo faccio un nuovo mess
                return(false);
            }

            switch (nuovaConn)
            { //Sono state messe in ordine di probabilità
            case NuovaConn.seNecessario:
                if (cmd.Connection == null || cmd.Connection.State != ConnectionState.Open)
                {
                    if (ConnettiDB(logMess) == false)
                    {
                        return(false);
                    }
                }
                break;

            case NuovaConn.no:     //Controllo che sia tutto ok per una nuova query, ma non devo fare altro
                if (cmd.Connection == null)
                {
                    logMess.testoDaLoggare = "nuovaConn = no ma cmd.Connection.State è nothing";
                    Log.main.Add(new Mess(LogType.ERR, "", logMess.testoDaLoggare));
                    return(false);
                }

                if (cmd.Connection.State != ConnectionState.Open)
                {
                    logMess.testoDaLoggare = "nuovaConn = no ma cmd.Connection.State diverso da open, state:<" + cmd.Connection.State.ToString() + ">";
                    Log.main.Add(new Mess(LogType.Warn, "", logMess.testoDaLoggare));
                    return(false);
                }
                break;

            case NuovaConn.si:
                if (ConnettiDB(logMess) == false)
                {
                    return(false);
                }
                if (this.connStr.DbRemoto == true)
                {
                    if (cmd.Connection == null || cmd.Connection.State != ConnectionState.Open)
                    {
                        return(false);
                    }
                }
                break;

            default:
                logMess.testoDaLoggare = "valore disatteso per nuovaConn:<" + nuovaConn.ToString() + ">";
                Log.main.Add(new Mess(LogType.ERR, Log.main.errUserText, logMess.testoDaLoggare));     //Qui ci vuole sempre errore indipendentemente da tipoLog
                return(false);
            }


            //If nuovaConn = True Then
            //    If ConnettiDB(Me.strConn, visualErr) = False Then Return False
            //    If Me.strConn.dbRemoto = True Then
            //        If IsNothing(cmd.Connection) = True OrElse cmd.Connection.State <> ConnectionState.Open Then Return False
            //    End If
            //Else
            //    If IsNothing(cmd.Connection) = False AndAlso cmd.Connection.State <> ConnectionState.Open Then 'In questo caso comunque sia non posso fare connettiDB(poichè potrebbero essere una serie di insert con ...
            //        log.Acc(New Mess(Tipi.avv, "", "nuovaConn = false ma cmd.Connection.State diverso da open, state:<" & cmd.Connection.State.ToString & ">")) '...commit finale, quindi fallirà l'esecuzione della query)
            //    End If
            //End If

            cmd.CommandText = query + "  --***Stack sub: " + Util.GetCallStack();

            return(true);
        }
示例#9
0
 public DalEXPPackingList()
 {
     _context    = new BLC_DEVEntities();
     _connString = StrConnection.GetConnectionString();
 }
示例#10
0
 public DalLoanReturnRequest()
 {
     _connString = StrConnection.GetConnectionString();
 }