Exemple #1
0
        internal void SetData(Report rpt, XmlDocument xmlDoc, Fields flds, Filters f)
        {
            if (xmlDoc == null)			// Does user want to remove user data?
            {
                SetMyUserData(rpt, null);
                return;
            }

            Rows rows = new Rows(rpt,null,null,null);		// no sorting and grouping at base data

            XmlNode xNode;
            xNode = xmlDoc.LastChild;
            if (xNode == null || !(xNode.Name == "Rows" || xNode.Name == "fyi:Rows"))
            {
                throw new Exception("XML Data must contain top level element Rows.");
            }

            List<Row> ar = new List<Row>();
            rows.Data = ar;

            int rowCount=0;
            int fieldCount = flds.Items.Count;
            foreach(XmlNode xNodeRow in xNode.ChildNodes)
            {
                if (xNodeRow.NodeType != XmlNodeType.Element)
                    continue;
                if (xNodeRow.Name != "Row")
                    continue;
                Row or = new Row(rows, fieldCount);
                foreach (XmlNode xNodeColumn in xNodeRow.ChildNodes)
                {
                    Field fld = (Field) (flds.Items[xNodeColumn.Name]);	// Find the column
                    if (fld == null)
                        continue;			// Extraneous data is ignored
                    if (xNodeColumn.InnerText == null || xNodeColumn.InnerText.Length == 0)
                        or.Data[fld.ColumnNumber] = null;
                    else if (fld.Type == TypeCode.String)
                        or.Data[fld.ColumnNumber] = xNodeColumn.InnerText;
                    else
                    {
                        try
                        {
                            or.Data[fld.ColumnNumber] =
                                Convert.ChangeType(xNodeColumn.InnerText, fld.Type, NumberFormatInfo.InvariantInfo);
                        }
                        catch	// all conversion errors result in a null value
                        {
                            or.Data[fld.ColumnNumber] = null;
                        }
                    }
                }
                // Apply the filters
                if (f == null || f.Apply(rpt, or))
                {
                    or.RowNumber = rowCount;	//
                    rowCount++;
                    ar.Add(or);
                }
            }

            ar.TrimExcess();		// free up any extraneous space; can be sizeable for large # rows
            if (f != null)
                f.ApplyFinalFilters(rpt, rows, false);

            SetMyUserData(rpt, rows);
        }
        string _XmlRowFile; //   - File should be loaded for user data; if not found use XmlRowData

        #endregion Fields

        #region Constructors

        internal DataSetDefn(ReportDefn r, ReportLink p, XmlNode xNode)
            : base(r, p)
        {
            _Name=null;
            _Fields=null;
            _Query=null;
            _CaseSensitivity=TrueFalseAutoEnum.True;
            _Collation=null;
            _AccentSensitivity=TrueFalseAutoEnum.False;
            _KanatypeSensitivity=TrueFalseAutoEnum.False;
            _WidthSensitivity=TrueFalseAutoEnum.False;
            _Filters=null;
            _HideDuplicates=null;
            // Run thru the attributes
            foreach(XmlAttribute xAttr in xNode.Attributes)
            {
                switch (xAttr.Name)
                {
                    case "Name":
                        _Name = new Name(xAttr.Value);
                        break;
                }
            }

            // Loop thru all the child nodes
            foreach(XmlNode xNodeLoop in xNode.ChildNodes)
            {
                if (xNodeLoop.NodeType != XmlNodeType.Element)
                    continue;
                switch (xNodeLoop.Name)
                {
                    case "Fields":
                        _Fields = new Fields(r, this, xNodeLoop);
                        break;
                    case "Query":
                        _Query = new Query(r, this, xNodeLoop);
                        break;
                    case "Rows":	// Extension !!!!!!!!!!!!!!!!!!!!!!!
                    case "fyi:Rows":
                        _XmlRowData = "<?xml version='1.0' encoding='UTF-8'?><Rows>" + xNodeLoop.InnerXml + "</Rows>";
                        foreach(XmlAttribute xA in xNodeLoop.Attributes)
                        {
                            if (xA.Name == "File")
                                _XmlRowFile = xA.Value;
                        }
                        break;
                    case "CaseSensitivity":
                        _CaseSensitivity = TrueFalseAuto.GetStyle(xNodeLoop.InnerText, OwnerReport.rl);
                        break;
                    case "Collation":
                        _Collation = xNodeLoop.InnerText;
                        break;
                    case "AccentSensitivity":
                        _AccentSensitivity = TrueFalseAuto.GetStyle(xNodeLoop.InnerText, OwnerReport.rl);
                        break;
                    case "KanatypeSensitivity":
                        _KanatypeSensitivity = TrueFalseAuto.GetStyle(xNodeLoop.InnerText, OwnerReport.rl);
                        break;
                    case "WidthSensitivity":
                        _WidthSensitivity = TrueFalseAuto.GetStyle(xNodeLoop.InnerText, OwnerReport.rl);
                        break;
                    case "Filters":
                        _Filters = new Filters(r, this, xNodeLoop);
                        break;
                    default:
                        OwnerReport.rl.LogError(4, "Unknown DataSet element '" + xNodeLoop.Name + "' ignored.");
                        break;
                }
            }
            if (this.Name != null)
                OwnerReport.LUAggrScope.Add(this.Name.Nm, this);		// add to referenceable TextBoxes
            else
                OwnerReport.rl.LogError(4, "Name attribute must be specified in a DataSet.");

            if (_Query == null)
                OwnerReport.rl.LogError(8, "Query element must be specified in a DataSet.");
        }
Exemple #3
0
        internal void SetData(Report rpt, DataTable dt, Fields flds, Filters f)
        {
            if (dt == null)			// Does user want to remove user data?
            {
                SetMyUserData(rpt, null);
                return;
            }

            Rows rows = new Rows(rpt,null,null,null);		// no sorting and grouping at base data

            List<Row> ar = new List<Row>();
            rows.Data = ar;
            int rowCount=0;
            int maxRows = _RowLimit > 0? _RowLimit: int.MaxValue;

            int fieldCount = flds.Items.Count;
            foreach (DataRow dr in dt.Rows)
                {
                Row or = new Row(rows, fieldCount);
                // Loop thru the columns obtaining the data values by name
                foreach (Field fld in flds.Items.Values)
                {
                    or.Data[fld.ColumnNumber] = dr[fld.DataField];
                }
                // Apply the filters
                if (f == null || f.Apply(rpt, or))
                {
                    or.RowNumber = rowCount;	//
                    rowCount++;
                    ar.Add(or);
                }
                if (--maxRows <= 0)				// don't retrieve more than max
                    break;
            }
            ar.TrimExcess();		// free up any extraneous space; can be sizeable for large # rows
            if (f != null)
                f.ApplyFinalFilters(rpt, rows, false);

            SetMyUserData(rpt, rows);
        }
Exemple #4
0
        internal void SetData(Report rpt, IDataReader dr, Fields flds, Filters f)
        {
            if (dr == null)			// Does user want to remove user data?
            {
                SetMyUserData(rpt, null);
                return;
            }

            Rows rows = new Rows(rpt,null,null,null);		// no sorting and grouping at base data

            List<Row> ar = new List<Row>();
            rows.Data = ar;
            int rowCount=0;
            int maxRows = _RowLimit > 0? _RowLimit: int.MaxValue;
            while (dr.Read())
            {
                Row or = new Row(rows, dr.FieldCount);
                dr.GetValues(or.Data);
                // Apply the filters
                if (f == null || f.Apply(rpt, or))
                {
                    or.RowNumber = rowCount;	//
                    rowCount++;
                    ar.Add(or);
                }
                if (--maxRows <= 0)				// don't retrieve more than max
                    break;
            }
            ar.TrimExcess();		// free up any extraneous space; can be sizeable for large # rows
            if (f != null)
                f.ApplyFinalFilters(rpt, rows, false);

            SetMyUserData(rpt, rows);
        }
Exemple #5
0
        internal void SetData(Report rpt, IEnumerable ie, Fields flds, Filters f)
        {
            if (ie == null)			// Does user want to remove user data?
            {
                SetMyUserData(rpt, null);
                return;
            }

            Rows rows = new Rows(rpt, null,null,null);		// no sorting and grouping at base data

            List<Row> ar = new List<Row>();
            rows.Data = ar;
            int rowCount=0;
            int maxRows = _RowLimit > 0? _RowLimit: int.MaxValue;
            int fieldCount = flds.Items.Count;
            foreach (object dt in ie)
            {
                // Get the type.
                Type myType = dt.GetType();

                // Build the row
                Row or = new Row(rows, fieldCount);

                // Go thru each field and try to obtain a value
                foreach (Field fld in flds)
                {
                    // Get the type and fields of FieldInfoClass.
                    FieldInfo fi = myType.GetField(fld.Name.Nm, BindingFlags.Instance | BindingFlags.Public);
                    if (fi != null)
                    {
                        or.Data[fld.ColumnNumber] = fi.GetValue(dt);
                    }
                    else
                    {
                        // Try getting it as a property as well
                        PropertyInfo pi = myType.GetProperty(fld.Name.Nm, BindingFlags.Instance | BindingFlags.Public);
                        if (pi != null)
                        {
                            or.Data[fld.ColumnNumber] = pi.GetValue(dt, null);
                        }
                    }
                }

                // Apply the filters
                if (f == null || f.Apply(rpt, or))
                {
                    or.RowNumber = rowCount;	//
                    rowCount++;
                    ar.Add(or);
                }
                if (--maxRows <= 0)				// don't retrieve more than max
                    break;
            }
            ar.TrimExcess();		// free up any extraneous space; can be sizeable for large # rows
            if (f != null)
                f.ApplyFinalFilters(rpt, rows, false);

            SetMyUserData(rpt, rows);
        }
Exemple #6
0
        // Obtain the data from the XML
        internal bool GetData(Report rpt, string xmlData, Fields flds, Filters f)
        {
            Rows uData = this.GetMyUserData(rpt);
            if (uData != null)
            {
                this.SetMyData(rpt, uData);
                return uData.Data == null || uData.Data.Count == 0? false: true;
            }

            int fieldCount = flds.Items.Count;

            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = false;
            doc.LoadXml(xmlData);

            XmlNode xNode;
            xNode = doc.LastChild;
            if (xNode == null || !(xNode.Name == "Rows" || xNode.Name == "fyi:Rows"))
            {
                throw new Exception("Error: XML Data must contain top level rows.");
            }

            Rows _Data = new Rows(rpt, null,null,null);
            List<Row> ar = new List<Row>();
            _Data.Data = ar;

            int rowCount=0;
            foreach(XmlNode xNodeRow in xNode.ChildNodes)
            {
                if (xNodeRow.NodeType != XmlNodeType.Element)
                    continue;
                if (xNodeRow.Name != "Row")
                    continue;
                Row or = new Row(_Data, fieldCount);
                foreach (XmlNode xNodeColumn in xNodeRow.ChildNodes)
                {
                    Field fld = (Field) (flds.Items[xNodeColumn.Name]);	// Find the column
                    if (fld == null)
                        continue;			// Extraneous data is ignored
                    TypeCode tc = fld.qColumn != null? fld.qColumn.colType: fld.Type;

                    if (xNodeColumn.InnerText == null || xNodeColumn.InnerText.Length == 0)
                        or.Data[fld.ColumnNumber] = null;
                    else if (tc == TypeCode.String)
                        or.Data[fld.ColumnNumber] = xNodeColumn.InnerText;
                    else if (tc == TypeCode.DateTime)
                    {
                        try
                        {
                            or.Data[fld.ColumnNumber] =
                                Convert.ToDateTime(xNodeColumn.InnerText,
                                System.Globalization.DateTimeFormatInfo.InvariantInfo);
                        }
                        catch	// all conversion errors result in a null value
                        {
                            or.Data[fld.ColumnNumber] = null;
                        }
                    }
                    else
                    {
                        try
                        {
                            or.Data[fld.ColumnNumber] =
                                Convert.ChangeType(xNodeColumn.InnerText, tc, NumberFormatInfo.InvariantInfo);
                        }
                        catch	// all conversion errors result in a null value
                        {
                            or.Data[fld.ColumnNumber] = null;
                        }
                    }
                }
                // Apply the filters
                if (f == null || f.Apply(rpt, or))
                {
                    or.RowNumber = rowCount;	//
                    rowCount++;
                    ar.Add(or);
                }
            }

            ar.TrimExcess();		// free up any extraneous space; can be sizeable for large # rows
            if (f != null)
                f.ApplyFinalFilters(rpt, _Data, false);

            SetMyData(rpt, _Data);
            return _Data == null || _Data.Data == null || _Data.Data.Count == 0 ? false : true;
        }
Exemple #7
0
        internal bool GetData(Report rpt, Fields flds, Filters f)
        {
            Rows uData = this.GetMyUserData(rpt);
            if (uData != null)
            {
                this.SetMyData(rpt, uData);
                return uData.Data == null || uData.Data.Count == 0 ? false : true;
            }

            // Treat this as a SQL statement
            DataSourceDefn ds = _DataSourceDefn;
            if (ds == null || _CommandText == null)
            {
                this.SetMyData(rpt, null);
                return false;
            }

            IDbConnection cnSQL = ds.SqlConnect(rpt);
            if (cnSQL == null)
            {
                this.SetMyData(rpt, null);
                return false;
            }

            Rows _Data = new Rows(rpt, null,null,null);		// no sorting and grouping at base data
            String sql = _CommandText.EvaluateString(rpt, null);
            IDbCommand cmSQL=null;
            IDataReader dr=null;
            try
            {
                cmSQL = cnSQL.CreateCommand();
                cmSQL.CommandText = AddParametersAsLiterals(rpt, cnSQL, sql, true);
                if (this._QueryCommandType == QueryCommandTypeEnum.StoredProcedure)
                    cmSQL.CommandType = CommandType.StoredProcedure;
                if (this._Timeout > 0)
                    cmSQL.CommandTimeout = this._Timeout;

                AddParameters(rpt, cnSQL, cmSQL, true);
                dr = cmSQL.ExecuteReader(CommandBehavior.SingleResult);

                List<Row> ar = new List<Row>();
                _Data.Data = ar;
                int rowCount=0;
                int maxRows = _RowLimit > 0? _RowLimit: int.MaxValue;
                int fieldCount = flds.Items.Count;

                // Determine the query column number for each field
                int[] qcn = new int[flds.Items.Count];
                foreach (Field fld in flds)
                {
                    qcn[fld.ColumnNumber] = -1;
                    if (fld.Value != null)
                        continue;
                    try
                    {
                        qcn[fld.ColumnNumber] = dr.GetOrdinal(fld.DataField);
                    }
                    catch
                    {
                        qcn[fld.ColumnNumber] = -1;
                    }
                }

                while (dr.Read())
                {
                    Row or = new Row(_Data, fieldCount);

                    foreach (Field fld in flds)
                    {
                        if (qcn[fld.ColumnNumber] != -1)
                        {
                            or.Data[fld.ColumnNumber] = dr.GetValue(qcn[fld.ColumnNumber]);
                        }
                    }

                    // Apply the filters
                    if (f == null || f.Apply(rpt, or))
                    {
                        or.RowNumber = rowCount;	//
                        rowCount++;
                        ar.Add(or);
                    }
                    if (--maxRows <= 0)				// don't retrieve more than max
                        break;
                }
                ar.TrimExcess();		// free up any extraneous space; can be sizeable for large # rows
                if (f != null)
                    f.ApplyFinalFilters(rpt, _Data, false);
            //#if DEBUG
            //				rpt.rl.LogError(4, "Rows Read:" + ar.Count.ToString() + " SQL:" + sql );
            //#endif
            }
            catch (Exception e)
            {
                rpt.rl.LogError(8, "SQL Exception" + e.Message + "\r\n" + e.StackTrace);
            }
            finally
            {
                if (cmSQL != null)
                {
                    cmSQL.Dispose();
                    if (dr != null)
                        dr.Close();
                }
            }
            this.SetMyData(rpt, _Data);
            return _Data == null || _Data.Data == null || _Data.Data.Count == 0 ? false : true;
        }