Exemple #1
0
        /// <summary>
        /// Get  licence info of a licences by id
        /// </summary>
        /// <param name="id">Id</param>
        /// <returns></returns>
        public static Licence GetInfo(string exePath)
        {
            string sql = "SELECT ExePath, Type, TimeInterval,MaxTime, ConcurrentLicences ,LastRunStart,LastRunEnd  , Enabled FROM " + TABLE_NAME + "  WHERE ExePath = {0} ";

            sql = string.Format(sql, SqliteDbHelper.SQLString(exePath));
            System.Data.DataSet transData = SqliteDbHelper.GetData(sql);
            if (transData != null)
            {
                if (transData.Tables.Count > 0)
                {
                    if (transData.Tables[0].Rows.Count > 0)
                    {
                        System.Data.DataRow dr      = transData.Tables[0].Rows[0];
                        Licence             Licence = new Licence(SqliteDbHelper.ToString(dr["ExePath"]));
                        Licence.Type               = (LicenceType)Enum.Parse(typeof(LicenceType), SqliteDbHelper.ToString(dr["Type"]));
                        Licence.TimeInterval       = SqliteDbHelper.ToInt(dr["TimeInterval"]);
                        Licence.MaxTime            = SqliteDbHelper.ToInt(dr["MaxTime"]);
                        Licence.ConcurrentLicences = SqliteDbHelper.ToInt(dr["ConcurrentLicences"]);
                        Licence.LastRunStart       = SqliteDbHelper.ToNullableDateTime(dr["LastRunStart"]);
                        Licence.LastRunEnd         = SqliteDbHelper.ToNullableDateTime(dr["LastRunEnd"]);
                        Licence.Enabled            = SqliteDbHelper.ToBoolean(dr["Enabled"]);
                        return(Licence);
                    }
                }
            }
            return(null);
        }
Exemple #2
0
        public bool InsertAndUpdate()
        {
            string  sql         = string.Empty;
            Licence transaction = Licence.GetInfo(this.OldExePath);

            if (transaction == null)
            {
                sql = string.Format("INSERT INTO " + TABLE_NAME + "  (ExePath, Type, TimeInterval,MaxTime,ConcurrentLicences,LastRunStart,LastRunEnd  , Enabled) Values ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7})", SqliteDbHelper.SQLString(this.ExePath), SqliteDbHelper.SQLString(this.Type.ToString()), SqliteDbHelper.SQLNumber(this.TimeInterval), SqliteDbHelper.SQLNumber(this.MaxTime), SqliteDbHelper.SQLNumber(this.ConcurrentLicences), SqliteDbHelper.SQLDateTime(this.LastRunStart), SqliteDbHelper.SQLDateTime(this.LastRunEnd), SqliteDbHelper.SQLBoolean(this.Enabled));
            }
            else
            {
                this.LastRunEnd   = transaction.LastRunEnd;
                this.LastRunStart = transaction.LastRunStart;
                sql = string.Format("UPDATE " + TABLE_NAME + "  Set Type = {1}, TimeInterval = {2}, MaxTime ={3}, ConcurrentLicences = {4}, LastRunStart={5}, LastRunEnd={6}, Enabled = {7},ExePath = {8} WHERE ExePath = {0} ", SqliteDbHelper.SQLString(this.OldExePath), SqliteDbHelper.SQLString(this.Type.ToString()), SqliteDbHelper.SQLNumber(this.TimeInterval), SqliteDbHelper.SQLNumber(this.MaxTime), SqliteDbHelper.SQLNumber(this.ConcurrentLicences), SqliteDbHelper.SQLDateTime(this.LastRunStart), SqliteDbHelper.SQLDateTime(this.LastRunEnd), SqliteDbHelper.SQLBoolean(this.Enabled), SqliteDbHelper.SQLString(this.ExePath));
            }

            if (string.IsNullOrEmpty(SqliteDbHelper.ExecuteQuery(sql)))
            {
                _Saved = true;
                _Dirty = false;
            }
            return(_Saved);
        }
Exemple #3
0
        /// <summary>
        /// Get all Licences
        /// </summary>
        /// <returns></returns>
        private static List <Licence> GetAllLicences(LicenceType type, bool?enabled = null)
        {
            List <Licence> Licences = new List <Licence>();
            string         sWHERE   = " WHERE ";
            string         sAND     = string.Empty;
            string         sql      = "SELECT ExePath, Type, TimeInterval,MaxTime, ConcurrentLicences ,LastRunStart,LastRunEnd  , Enabled FROM " + TABLE_NAME;

            switch (type)
            {
            case LicenceType.TRIGGERBASE:
                sql    = sql + sWHERE + sAND + " Type = 'TRIGGERBASE' ";
                sWHERE = string.Empty;
                sAND   = " AND ";
                break;

            case LicenceType.PERIODIC:
                sql    = sql + sWHERE + sAND + " Type = 'PERIODIC' ";
                sWHERE = string.Empty;
                sAND   = " AND ";
                break;

            case LicenceType.NONE:
                break;
            }
            if (enabled.HasValue)
            {
                if (enabled.Value)
                {
                    sql = sql + sWHERE + sAND + " Enabled = '1'";
                }
                else
                {
                    sql = sql + sWHERE + sAND + " Enabled = '0'";
                }

                sWHERE = string.Empty;
                sAND   = " AND ";
            }
            System.Data.DataSet transData = SqliteDbHelper.GetData(sql);
            if (transData != null)
            {
                if (transData.Tables.Count > 0)
                {
                    if (transData.Tables[0].Rows.Count > 0)
                    {
                        foreach (System.Data.DataRow dr in transData.Tables[0].Rows)
                        {
                            Licence Licence = new Licence(SqliteDbHelper.ToString(dr["ExePath"]));

                            Licence.Type               = (LicenceType)Enum.Parse(typeof(LicenceType), SqliteDbHelper.ToString(dr["Type"]));
                            Licence.TimeInterval       = SqliteDbHelper.ToInt(dr["TimeInterval"]);
                            Licence.MaxTime            = SqliteDbHelper.ToInt(dr["MaxTime"]);
                            Licence.ConcurrentLicences = SqliteDbHelper.ToInt(dr["ConcurrentLicences"]);
                            Licence.LastRunStart       = SqliteDbHelper.ToNullableDateTime(dr["LastRunStart"]);
                            Licence.LastRunEnd         = SqliteDbHelper.ToNullableDateTime(dr["LastRunEnd"]);
                            Licence.Enabled            = SqliteDbHelper.ToBoolean(dr["Enabled"]);
                            Licences.Add(Licence);
                        }
                    }
                }
            }
            return(Licences);
        }