Beispiel #1
0
        /// <summary>
        /// Executes the specified count only.
        /// </summary>
        /// <param name="countOnly">
        /// if set to <c>true</c> [count only].
        /// </param>
        /// <returns>
        /// The <see cref="GenericRecordSet"/>.
        /// </returns>
        public GenericRecordSet Execute(bool countOnly)
        {
            var recordSet = new DatabaseRecordSet(this.crmDatabase);
            var context   = new StatementCreationContext(this);

            var statementString = this.CreateStatement(context, countOnly);

            if (!string.IsNullOrEmpty(context.ErrorText))
            {
                // _crmDatabase.Trace(_crmDatabase, context.GetErrorText());
                return(null);
            }

            var parameterList  = context.ParameterValues;
            var parameterCount = parameterList?.Count ?? 0;

            if (parameterCount > 0)
            {
                recordSet.Execute(statementString, parameterList?.ToArray(), this.MaxResultRowCount);
            }
            else
            {
                recordSet.Execute(statementString, this.MaxResultRowCount);
            }

            if (recordSet.GetRowCount() > 0 && this.RootTreeItem.HasSubQueries())
            {
                var joinedRecordSet = this.RootTreeItem.ExecuteSubQueries(recordSet);
                return(joinedRecordSet);
            }

            return(recordSet);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the select query.
        /// </summary>
        /// <returns>
        /// The <see cref="DatabaseRecordSet"/>.
        /// </returns>
        public DatabaseRecordSet GetSelectQuery()
        {
            if (this.selectStatement != null)
            {
                return(this.selectStatement);
            }

            this.selectStatement = new DatabaseRecordSet(this.Database);
            if (!this.selectStatement.Query.Prepare(this.GetSelectStatementString()))
            {
                this.selectStatement = null;
            }

            return(this.selectStatement);
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RecordTemplate"/> class.
        /// </summary>
        /// <param name="database">
        /// The database.
        /// </param>
        /// <param name="infoAreaId">
        /// The information area identifier.
        /// </param>
        /// <param name="fieldIdCount">
        /// The field identifier count.
        /// </param>
        /// <param name="fieldids">
        /// The fieldids.
        /// </param>
        /// <param name="linkFieldNameCount">
        /// The link field name count.
        /// </param>
        /// <param name="linkFieldNames">
        /// The link field names.
        /// </param>
        public RecordTemplate(
            CRMDatabase database,
            string infoAreaId,
            int fieldIdCount,
            FieldIdType[] fieldids,
            int linkFieldNameCount,
            List <string> linkFieldNames)
        {
            this.Database     = database;
            this.InfoAreaId   = infoAreaId;
            this.FieldIdCount = fieldIdCount;
            this.fieldIds     = fieldids;

            this.LinkFieldNameCount = linkFieldNameCount;
            if (linkFieldNames != null && linkFieldNameCount > 0)
            {
                this.linkFieldNames = new List <string>();
                for (var i = 0; i < linkFieldNameCount; i++)
                {
                    this.linkFieldNames.Add(linkFieldNames[i]);
                }
            }
            else
            {
                this.linkFieldNames = null;
            }

            this.insertStatementString = null;
            this.updateStatementString = null;
            this.selectStatementString = null;
            this.existsStatementString = null;
            this.deleteStatementString = null;
            this.tableinfo             = null;
            this.insertStatement       = null;
            this.updateStatement       = null;
            this.selectStatement       = null;
            this.existsStatement       = null;
            this.deleteStatement       = null;
        }
Beispiel #4
0
        /// <summary>
        /// Loads this instance.
        /// </summary>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int Load()
        {
            var tableRecordSet = new DatabaseRecordSet(this.Database);

            tableRecordSet.Query.Prepare("SELECT infoareaid, rootinfoareaid, name, haslookup FROM tableinfo");

            TableInfo   tableinfo;
            DatabaseRow row;
            var         ret            = tableRecordSet.Execute();
            var         tableInfoCount = tableRecordSet.GetRowCount();

            for (var i = 0; i < tableInfoCount; i++)
            {
                row       = tableRecordSet.GetRow(i);
                tableinfo = this.AddTableInfo(
                    row.GetColumn(0),
                    row.GetColumn(1),
                    row.GetColumn(2),
                    row.GetColumnInt(3, 0));
                tableinfo.Load(this.Database);
            }

            for (var i = 0; i < tableInfoCount; i++)
            {
                tableinfo = this.TableInfos[i];
                if (!string.IsNullOrEmpty(tableinfo.RootInfoAreaId))
                {
                    var parent = this.Database.GetTableInfoByInfoArea(tableinfo.RootInfoAreaId);
                    parent?.AddSpecialInfoArea(tableinfo);
                }
            }

            var catalogRecordSet = new DatabaseRecordSet(this.Database);

            catalogRecordSet.Query.Prepare("SELECT catnr FROM fixcatinfo");
            catalogRecordSet.Execute();

            var catalogInfoCount = catalogRecordSet.GetRowCount();

            for (var i = 0; i < catalogInfoCount; i++)
            {
                row = catalogRecordSet.GetRow(i);
                this.AddFixedCatalog(row.GetColumnInt(0));
            }

            catalogRecordSet = new DatabaseRecordSet(this.Database);
            catalogRecordSet.Query.Prepare("SELECT catnr, parentcatnr FROM varcatinfo");
            if (ret == 0)
            {
                ret = catalogRecordSet.Execute();
            }

            catalogInfoCount = catalogRecordSet.GetRowCount();
            for (var i = 0; i < catalogInfoCount; i++)
            {
                row = catalogRecordSet.GetRow(i);
                if (row.IsNull(1))
                {
                    this.AddVariableCatalog(row.GetColumnInt(0));
                }
                else
                {
                    this.AddVariableCatalog(row.GetColumnInt(0), row.GetColumnInt(1));
                }
            }

            this.Sort(true);

            return(ret);
        }
Beispiel #5
0
        /// <summary>
        /// Creates the value set.
        /// </summary>
        /// <param name="parentCode">
        /// The parent code.
        /// </param>
        /// <returns>
        /// The <see cref="CatalogValueSet"/>.
        /// </returns>
        public virtual CatalogValueSet CreateValueSet(int parentCode)
        {
            // bool variable, dep;
            // SYS_CHAR tableName[MAX_CATALOG_TABLENAME];
            var catalogValueRecordSet = new DatabaseRecordSet(this.Database);

            var memorybuffer = new StringBuilder();

            memorybuffer.Append("SELECT code, text, sortinfo, access");

            if (this.IsVariable)
            {
                memorybuffer.Append(", extkey, tenant");
            }

            if (this.IsDependent)
            {
                memorybuffer.Append(", parentcode");
            }

            memorybuffer.Append(" FROM ");
            memorybuffer.Append(this.GetDatabaseTableName());

            var parameterCount = 0;

            if (this.IsDependent && parentCode >= 0)
            {
                memorybuffer.Append($" WHERE parentcode = {parentCode}");
                parameterCount = 1;
            }

            var returnString = memorybuffer.ToString();

            int             ret;
            CatalogValueSet values = null;

            if (parameterCount > 0)
            {
                ret = catalogValueRecordSet.Execute(returnString, new[] { $"{parentCode}" }, 0);
            }
            else
            {
                ret = catalogValueRecordSet.Query.Prepare(returnString) ? 0 : 1;
                if (ret == 0)
                {
                    ret = catalogValueRecordSet.Execute();
                }
            }

            if (ret == 0)
            {
                values = new CatalogValueSet {
                    SortFunction = this.GetSortFunction
                };

                int         i, catalogValueCount = catalogValueRecordSet.RowCount;
                DatabaseRow row;
                for (i = 0; i < catalogValueCount; i++)
                {
                    row = catalogValueRecordSet.GetRow(i);
                    if (this.IsDependent)
                    {
                        values.AddDependentCatalogValue(
                            row.GetColumnInt(0),
                            row.GetColumnInt(6),
                            row.GetColumn(1),
                            row.GetColumnInt(5),
                            row.GetColumn(4),
                            row.GetColumnInt(2),
                            row.GetColumnInt(3));
                    }
                    else if (this.IsVariable)
                    {
                        values.AddVariableCatalogValue(
                            row.GetColumnInt(0),
                            row.GetColumn(1),
                            row.GetColumnInt(5),
                            row.GetColumn(4),
                            row.GetColumnInt(2),
                            row.GetColumnInt(3));
                    }
                    else
                    {
                        values.AddFixedCatalogValue(
                            row.GetColumnInt(0),
                            row.GetColumn(1),
                            row.GetColumnInt(2),
                            row.GetColumnInt(3));
                    }
                }
            }

            if (values == null)
            {
                values = new CatalogValueSet();
            }

            values.Sort();
            return(values);
        }