Exemplo n.º 1
0
        /*******************************************************************************************************/
        #region DATABASE METHODS

        public static DataRow get(Guid?id)
        {
            SqlQueryResult result = DBConnection.query(
                false,
                DBConnection.ActiveSqlConnection,
                QueryTypes.FillByAdapter,
                "Settings_get",
                new SqlQueryParameter(COL_DB_Id, SqlDbType.UniqueIdentifier, Util.wrapNullable(id))
                );

            return(Util.getFirstRow(result.Datatable));
        }
Exemplo n.º 2
0
        public static bool isRegistered()
        {
            string         hashedMACAddress = Util.hashStringWithoutSalt(Util.getMACAddress());
            SqlQueryResult result           = DBConnection.query(
                false,
                DBConnection.ActiveSqlConnection,
                QueryTypes.ExecuteNonQuery,
                false, false, false, true, false,
                "LicensedDevices_isExist_HashedMACAddress",
                new SqlQueryParameter(COL_DB_HashedMACAddress, SqlDbType.NVarChar, hashedMACAddress)
                );

            isDeviceRegistered = result.ValueBoolean;
            return(result.ValueBoolean);
        }
Exemplo n.º 3
0
        public void execute()
        {
            isQueryCompleted = false;

            if (sqlConnection != null)
            {
                result = DBConnection.executeQuery(sqlConnection, querytype, hasReturnValueString, hasReturnValueInt, hasReturnValueDecimal, hasReturnValueBoolean, hasReturnValueGuid, storedprocedurename, tableparameters, parameters);
            }
            else
            {
                using (SqlConnection sqlConnection = new SqlConnection(DBConnection.ConnectionString))
                    result = DBConnection.executeQuery(sqlConnection, querytype, hasReturnValueString, hasReturnValueInt, hasReturnValueDecimal, hasReturnValueBoolean, hasReturnValueGuid, storedprocedurename, tableparameters, parameters);
            }

            isQueryCompleted = true;
        }
Exemplo n.º 4
0
        public static void update(Guid id, int?intValue, string stringValue, bool?boolValue, DateTime?datetimeValue)
        {
            if (boolValue != null)
            {
                intValue = Util.convertToInt((bool)boolValue);
            }

            SqlQueryResult result = DBConnection.query(
                false,
                DBConnection.ActiveSqlConnection,
                QueryTypes.ExecuteNonQuery,
                "Settings_update",
                new SqlQueryParameter(COL_DB_Id, SqlDbType.UniqueIdentifier, id),
                new SqlQueryParameter(COL_DB_Value_Int, SqlDbType.Int, Util.wrapNullable(intValue)),
                new SqlQueryParameter(COL_DB_Value_String, SqlDbType.VarChar, Util.wrapNullable(stringValue)),
                new SqlQueryParameter(COL_DB_Value_DateTime, SqlDbType.DateTime, Util.wrapNullable(datetimeValue))
                );
        }
Exemplo n.º 5
0
        public static void addDevice()
        {
            string         hashedMACAddress = Util.hashStringWithoutSalt(Util.getMACAddress());
            Guid           Id     = Guid.NewGuid();
            SqlQueryResult result = DBConnection.query(
                false,
                DBConnection.ActiveSqlConnection,
                QueryTypes.ExecuteNonQuery,
                "LicensedDevices_add",
                new SqlQueryParameter(COL_DB_Id, SqlDbType.UniqueIdentifier, Id),
                new SqlQueryParameter(COL_DB_HashedMACAddress, SqlDbType.NVarChar, hashedMACAddress)
                );

            if (result.IsSuccessful)
            {
                isDeviceRegistered = true;
                Util.displayMessageBoxSuccess("License is valid. Thank you!");
            }
        }
Exemplo n.º 6
0
        public static SqlQueryResult executeQuery(SqlConnection sqlConnection, QueryTypes querytype,
                                                  bool hasReturnValueString, bool hasReturnValueInt, bool hasReturnValueDecimal, bool hasReturnValueBoolean, bool hasReturnValueGuid,
                                                  string storedprocedurename, SqlQueryTableParameter[] tableparameters, params SqlQueryParameter[] parameters)
        {
            SqlQueryResult result             = new SqlQueryResult();
            SqlParameter   returnValueString  = null;
            SqlParameter   returnValueInt     = null;
            SqlParameter   returnValueDecimal = null;
            SqlParameter   returnValueBoolean = null;
            SqlParameter   returnValueGuid    = null;

            try
            {
                using (SqlCommand cmd = new SqlCommand(storedprocedurename, sqlConnection))
                    using (SqlDataAdapter adapter = new SqlDataAdapter())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        if (parameters != null && parameters.Length > 0)
                        {
                            foreach (SqlQueryParameter parameter in parameters)
                            {
                                cmd.Parameters.Add("@" + parameter.ColumnName, parameter.SqlDbType).Value = parameter.Value;
                            }
                        }

                        if (tableparameters != null && tableparameters.Length > 0)
                        {
                            foreach (SqlQueryTableParameter tableparameter in tableparameters)
                            {
                                Util.addListParameter(cmd, "@" + tableparameter.ColumnName, tableparameter.Values);
                            }
                        }

                        if (hasReturnValueString)
                        {
                            returnValueString           = cmd.Parameters.Add("@returnValueString", SqlDbType.NVarChar, 100);
                            returnValueString.Direction = ParameterDirection.Output;
                        }
                        if (hasReturnValueInt)
                        {
                            returnValueInt           = cmd.Parameters.Add("@returnValueInt", SqlDbType.Int);
                            returnValueInt.Direction = ParameterDirection.Output;
                        }
                        if (hasReturnValueDecimal)
                        {
                            returnValueDecimal           = cmd.Parameters.Add("@returnValueDecimal", SqlDbType.Decimal);
                            returnValueDecimal.Direction = ParameterDirection.Output;
                        }
                        if (hasReturnValueBoolean)
                        {
                            returnValueBoolean           = cmd.Parameters.Add("@returnValueBoolean", SqlDbType.Bit);
                            returnValueBoolean.Direction = ParameterDirection.Output;
                        }
                        if (hasReturnValueGuid)
                        {
                            returnValueGuid           = cmd.Parameters.Add("@returnValueGuid", SqlDbType.UniqueIdentifier);
                            returnValueGuid.Direction = ParameterDirection.Output;
                        }

                        //open connection
                        if (sqlConnection.State != ConnectionState.Open)
                        {
                            sqlConnection.Open();
                        }

                        //execute command
                        if (querytype == QueryTypes.ExecuteNonQuery)
                        {
                            cmd.ExecuteNonQuery();
                        }
                        else if (querytype == QueryTypes.FillByAdapter)
                        {
                            adapter.SelectCommand = cmd;
                            result.Datatable      = new DataTable();
                            adapter.Fill(result.Datatable);
                        }

                        if (hasReturnValueString)
                        {
                            result.ValueString = returnValueString.Value.ToString();
                        }
                        if (hasReturnValueInt)
                        {
                            result.ValueInt = Convert.ToInt32(returnValueInt.Value);
                        }
                        if (hasReturnValueDecimal)
                        {
                            result.ValueDecimal = Convert.ToDecimal(returnValueDecimal.Value);
                        }
                        if (hasReturnValueBoolean)
                        {
                            result.ValueBoolean = Convert.ToBoolean(returnValueBoolean.Value);
                        }
                        if (hasReturnValueGuid)
                        {
                            if (returnValueGuid.Value != DBNull.Value)
                            {
                                result.ValueGuid = (Guid)returnValueGuid.Value;
                            }
                        }

                        result.IsSuccessful = true;

                        if (!_MultipleSQLConnectionUse)
                        {
                            sqlConnection.Close();
                        }
                    }
            }
            catch (Exception ex) { result.IsSuccessful = false; Util.displayMessageBoxError(ex.Message); }

            return(result);
        }