Ejemplo n.º 1
0
        /// <summary>
        /// Evaluates the specified query
        /// </summary>
        /// <typeparam name="T">Generic type</typeparam>
        /// <param name="t">Object type</param>
        /// <param name="dataSource">Datasource for evaluation</param>
        /// <param name="condition">Query to evaluate</param>
        /// <returns>Returns a XmlElement array which contains the selected data</returns>
        public object Evaluate <T>(T t, object dataSource, string condition)
        {
            DataTableQueryEvaluator eval = null;

            XmlElement[] nodes = null;

            try
            {
                eval = new DataTableQueryEvaluator();

                XmlDataDocument xdoc = (XmlDataDocument)dataSource;

                DataRow[] rows = (DataRow[])eval.Evaluate <DataTable>(xdoc.DataSet.Tables[0], xdoc.DataSet.Tables[0], condition);

                nodes = new XmlElement[eval.EvaluatorIndexes.Count];

                for (int i = 0; i < eval.EvaluatorIndexes.Count; i++)
                {
                    nodes[i] = xdoc.GetElementFromRow(xdoc.DataSet.Tables[0].Rows[eval.EvaluatorIndexes[i]]);
                }

                return((object)nodes);
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the sum of the field
        /// </summary>
        /// <param name="dataSource">The data source</param>
        /// <param name="fieldName">Name of the field</param>
        /// <returns>Returs the sum of the specified field</returns>
        public decimal Sum <T>(object dataSource, string fieldName, string query)
        {
            DataTableQueryEvaluator eval = null;

            try
            {
                eval = new DataTableQueryEvaluator();

                XmlDataDocument xdoc = (XmlDataDocument)dataSource;

                decimal result = Convert.ToDecimal(eval.Sum <DataTable>(xdoc.DataSet.Tables[0], fieldName, query));

                return(result);
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Evaluates the minimum value.
        /// </summary>
        /// <param name="t">Type to evaluate</param>
        /// <param name="dataSource">Data source</param>
        /// <param name="fieldName">Field name foe which the evaluation is made</param>
        /// <returns>XmlElement which contains the resulting field</returns>
        public object EvaluateMin <T>(T t, object dataSource, string fieldName)
        {
            DataTableQueryEvaluator eval = null;
            XmlElement element           = null;

            try
            {
                eval = new DataTableQueryEvaluator();

                XmlDataDocument xdoc = (XmlDataDocument)dataSource;

                DataRow row = (DataRow)eval.EvaluateMin <DataTable>(xdoc.DataSet.Tables[0], xdoc.DataSet.Tables[0], fieldName);

                element = xdoc.GetElementFromRow(xdoc.DataSet.Tables[0].Rows[eval.EvaluatorIndexes[0]]);

                return(element);
            }
            catch
            {
                throw;
            }
        }