예제 #1
0
        public virtual object GetParameterValue(IPDFDataSetProviderCommand command, PDFDataContext context)
        {
            string value = this.Value;

            if (string.IsNullOrEmpty(value))
            {
                value = this.DefaultValue;
            }

            if (String.IsNullOrEmpty(value))
            {
                //Special case where the data type is textual, and we are not null.
                if (this.IsStringDataType && null != value)
                {
                    return(String.Empty);
                }
                else
                {
                    return(command.GetNullValue(this.DataType));
                }
            }
            else
            {
                object parsed = TypeConverter.GetNativeValue(this.DataType, value);
                return(parsed);
            }
        }
예제 #2
0
        /// <summary>
        /// Fills the data into the dataset from the releated command, and then adds the relation constraint to the data set.
        /// </summary>
        /// <param name="rel"></param>
        /// <param name="ds"></param>
        /// <param name="source"></param>
        /// <param name="context"></param>
        protected virtual void FillRelatedData(DataRelation rel, DataSet ds, XPathDataSourceBase source, PDFDataContext context)
        {
            string cmd = rel.ChildCommand;
            XPathProviderCommandBase provider = source.Commands[cmd];

            if (null == provider)
            {
                throw new NullReferenceException(string.Format(Errors.CommandWithNameCannotBeFound, cmd, source.ID));
            }
            if (!(provider is IPDFDataSetProviderCommand))
            {
                throw new InvalidCastException(string.Format(Errors.CommandForRelatedDataMustMatchType, typeof(SqlProviderCommand), typeof(SqlProviderCommand)));
            }

            IPDFDataSetProviderCommand dsProvider = (IPDFDataSetProviderCommand)provider;

            dsProvider.FillData(ds, source, this, context);

            rel.AddRelation(this, dsProvider, ds, context);
        }
예제 #3
0
 /// <summary>
 /// Creates and adds the relation to the specified dataset.
 /// </summary>
 /// <param name="owner">The command on which this relation is defined</param>
 /// <param name="dataset">The dataset to add the relation to</param>
 public abstract void AddRelation(IPDFDataSetProviderCommand parent, IPDFDataSetProviderCommand child, DataSet dataset, PDFDataContext context);
        public override void AddRelation(IPDFDataSetProviderCommand parentCommand, IPDFDataSetProviderCommand childCommand, System.Data.DataSet dataset, PDFDataContext context)
        {
            string childtablename = childCommand.GetDataTableName(dataset);

            if (string.IsNullOrEmpty(childtablename))
            {
                throw new ArgumentNullException("owner.CommandName");
            }

            string parenttablename = parentCommand.GetDataTableName(dataset);

            if (string.IsNullOrEmpty(parenttablename))
            {
                throw new ArgumentNullException("this.Parent");
            }

            int matchcount = this.MatchOn.Count;

            if (matchcount < 1)
            {
                throw new ArgumentOutOfRangeException("this.MatchOn");
            }

            DataTable child = dataset.Tables[childtablename];

            if (null == child)
            {
                context.TraceLog.Add(TraceLevel.Message, SqlProviderCommand.SqlCommandLog, "Relation not created between '" + childtablename + "' and '" + parenttablename + "' as one or more tables are not in data set");
                return;
            }
            DataTable parent = dataset.Tables[parenttablename];

            if (null == parent)
            {
                context.TraceLog.Add(TraceLevel.Message, SqlProviderCommand.SqlCommandLog, "Relation not created between '" + childtablename + "' and '" + parenttablename + "' as one or more tables are not in data set");
                return;
            }

            DataColumn[] childmatches  = new DataColumn[matchcount];
            DataColumn[] parentmatches = new DataColumn[matchcount];

            for (int i = 0; i < matchcount; i++)
            {
                DataRelationMatch match = this.MatchOn[i];

                if (string.IsNullOrEmpty(match.ChildName))
                {
                    throw new NullReferenceException(string.Format(Errors.NullChildColumnForRelationToTable, childtablename, parentCommand.ID));
                }

                DataColumn col = child.Columns[match.ChildName];
                if (null == col)
                {
                    throw new NullReferenceException(string.Format(Errors.TableDoesNotContainColumn, match.ChildName, parentCommand.ID, childtablename));
                }

                childmatches[i] = col;

                if (string.IsNullOrEmpty(match.ParentName))
                {
                    throw new NullReferenceException(string.Format(Errors.NullParentColumnForRelationToTable, parenttablename, parentCommand.ID));
                }

                col = parent.Columns[match.ParentName];
                if (null == col)
                {
                    throw new NullReferenceException(string.Format(Errors.TableDoesNotContainColumn, match.ParentName));
                }

                parentmatches[i] = col;
            }

            System.Data.DataRelation rel = new System.Data.DataRelation(childtablename + "_2_" + parenttablename, parentmatches, childmatches);
            rel.Nested = true;

            dataset.Relations.Add(rel);
        }
예제 #5
0
        //
        // IPDFDataSetProvider implementation
        //

        #region public abstract void FillData(DataSet dataset, PDFXPathDataSourceBase source, IPDFDataSetProviderCommand parent, PDFDataContext context);

        /// <summary>
        /// Abstract base method that inheritors must override to populate the main data in this provider
        /// </summary>
        /// <param name="dataset"></param>
        /// <param name="source"></param>
        /// <param name="parent"></param>
        /// <param name="context"></param>
        public abstract void FillData(DataSet dataset, XPathDataSourceBase source, IPDFDataSetProviderCommand parent, PDFDataContext context);
        //
        // support methods
        //


        #region public void FillData(DataSet ds, PDFProviderParameterValueCollection values)

        /// <summary>
        /// Loads all the required data from this commands Sql source into the dataset using the
        /// Sql statement and the provided parameter values that have ben explicitly set
        /// </summary>
        /// <param name="ds">the DataSet to populate</param>
        /// <param name="index">The index of the command</param>
        public override void FillData(DataSet ds, XPathDataSourceBase source, IPDFDataSetProviderCommand parent, PDFDataContext context)
        {
            bool logDebug = context.TraceLog.ShouldLog(TraceLevel.Debug);

            if (logDebug)
            {
                context.TraceLog.Begin(TraceLevel.Debug, SqlCommandLog, string.Format("Starting load of data for sqlCommand '{0}'", this.ID));
            }

            DbConnection con = null;
            DbCommand    cmd = null;

            try
            {
                con = this.CreateConnection(source, parent as SqlProviderCommand);//parent could be null but handled in the code

                if (logDebug)
                {
                    context.TraceLog.Add(TraceLevel.Debug, SqlCommandLog, "Created db connection to sql database");
                }

                cmd = this.CreateCommand(con, this.CommandType, this.Statement);
                if (logDebug)
                {
                    context.TraceLog.Add(TraceLevel.Debug, SqlCommandLog, "Created db command for statement");
                }

                this.PopulateParameters(cmd, context);

                if (logDebug)
                {
                    context.TraceLog.Add(TraceLevel.Debug, SqlCommandLog, "Added " + cmd.Parameters.Count + " parameters to db command");
                }

                con.Open();
                this.PopulateData(ds, cmd);

                if (!string.IsNullOrEmpty(this.AsAttributes))
                {
                    ApplyAttributes(ds, this.AsAttributes, context);
                }

                if (logDebug)
                {
                    context.TraceLog.Add(TraceLevel.Debug, SqlCommandLog, "Dataset populated");
                }
            }
            finally
            {
                if (null != cmd)
                {
                    cmd.Dispose();
                }
                if (null != con)
                {
                    con.Dispose();
                }

                if (logDebug)
                {
                    context.TraceLog.Add(TraceLevel.Debug, SqlCommandLog, string.Format("Disposed of command and connection"));
                }
            }

            if (logDebug)
            {
                context.TraceLog.End(TraceLevel.Debug, SqlCommandLog, string.Format("Completed load of data for sqlCommand '{0}'", this.ID));
            }
        }