示例#1
0
        //
        //
        // *************************************
        // ****         GetReadQuery        ****
        // *************************************
        private string GetReadQuery(DatabaseInfo dataBase)
        {
            TableInfo.UVStrategiesTableInfo strategyTable = dataBase.UVStrategies;
            // Start of query
            StringBuilder query = new StringBuilder();

            /*
             * query.AppendFormat("SELECT * FROM {0}", strategyTable.TableNameFull);
             *
             * // Conditions
             * StringBuilder cond = new StringBuilder();
             * if (m_GroupId != null)
             * {
             *  if (m_GroupId.Count == 1)
             *  {
             *      if (cond.Length > 0)
             *          cond.Append(" AND");
             *      cond.AppendFormat(" {0}={1}", strategyTable.GroupID, m_GroupId[0]);
             *  }
             *  else if (m_GroupId.Count > 1)
             *  {
             *      if (cond.Length > 0)
             *          cond.Append(" AND");
             *      cond.AppendFormat(" {0} in ({1}", strategyTable.GroupID, m_GroupId[0]);
             *      for (int n = 1; n < m_GroupId.Count; ++n)
             *          cond.AppendFormat(",{0}", m_GroupId[n]);
             *      cond.Append(")");
             *  }
             * }
             *
             * // Now append them together.
             * if (cond.Length > 0)
             *  query.AppendFormat(" WHERE{0}", cond.ToString());
             * query.Append(";");
             */
            return(query.ToString());
        }// GetReadQuery()
示例#2
0
        //
        //
        // *************************************************
        // ****             AcceptData()                ****
        // *************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="dbInfo"></param>
        /// <param name="values"></param>
        /// <param name="fieldNames"></param>
        /// <returns></returns>
        public override QueryStatus AcceptData(DatabaseInfo dbInfo, List <object> values, List <string> fieldNames)
        {
            TableInfo.UVStrategiesTableInfo strategyTable = dbInfo.UVStrategies;

            /*
             * if (this.Results == null)
             *  this.Results = new List<StrategyQueryItem>();
             * else
             *  this.Results.Clear();
             *
             * // Extract  values.
             * int ptr = 0;                                // ptr to current data value
             * int fptr = 0;                               // ptr to associated field
             * int n;                                      // dummy variables..
             * DateTime dt;
             * TimeSpan ts;
             * StrategyQueryItem item = new StrategyQueryItem();   // place to store first strategy row
             * while (ptr < values.Count)
             * {
             *  object o = values[ptr];                 // load the value
             *  if (o != null)
             *  {
             *      // Extract data
             *      string s = o.ToString();
             *      string fieldName = fieldNames[fptr];
             *      if (fieldName.Equals(strategyTable.StrategyId) && int.TryParse(s, out n))
             *          item.StrategyId = n;
             *      else if (fieldName.Equals(strategyTable.GroupID) && int.TryParse(s, out n))
             *          item.GroupId = n;
             *      else if (fieldName.Equals(strategyTable.StrategyName))
             *          item.Name = s;
             *      else if (fieldName.Equals(strategyTable.RunType))
             *          item.RunType = s;
             *      //
             *      // start/end times
             *      //
             *      else if (fieldName.Equals(strategyTable.StartDate) && DateTime.TryParse(s, out dt))
             *          item.StartDate = dt;
             *      else if (fieldName.Equals(strategyTable.StartTime) && TimeSpan.TryParse(s, out ts))
             *          item.StartTime = ts;
             *      else if (fieldName.Equals(strategyTable.EndDate) && DateTime.TryParse(s, out dt))
             *          item.EndDate = dt;
             *      else if (fieldName.Equals(strategyTable.EndTime) && TimeSpan.TryParse(s, out ts))
             *          item.EndTime = ts;
             *      //
             *      // Parameters
             *      //
             *      else if (fieldName.Equals(strategyTable.Attributes))
             *          item.AttributeString = s;
             *
             *  }
             *  // Increment pointers
             *  ptr++;
             *  fptr = (fptr + 1) % fieldNames.Count;
             *  if (fptr == 0)                          // We have read all fields.. we have completed this row.
             *  {
             *      this.Results.Add(item);             // save this current row,
             *      item = new StrategyQueryItem();       // create a new object to hold the next row.
             *  }
             * }//next value
             */
            // Exit;
            return(QueryStatus.Completed);
        }//
示例#3
0
        //
        //
        //
        #endregion//Constructors


        #region Public Methods
        // *************************************
        // ****            GetQuery         ****
        // *************************************
        public override string GetQuery(DatabaseInfo dataBase)
        {
            TableInfo.UVStrategiesTableInfo strategyTable = dataBase.UVStrategies;
            // Start of query
            StringBuilder query = new StringBuilder();

            query.AppendFormat("SELECT * FROM {0}", strategyTable.TableNameFull);

            // Conditions
            StringBuilder cond = new StringBuilder();

            //
            // GroupId and StrategyId conditions
            //
            bool groupIdCondition    = (m_GroupId != null && m_GroupId.Count > 0);              // user has groupIds
            bool strategyIdCondition = (m_StrategyIds != null && m_StrategyIds.Count > 0);      // user has strategyIds

            if (groupIdCondition || strategyIdCondition)
            {   // These are handled together since they will be "OR" conditions.
                if (cond.Length > 0)
                {
                    cond.Append(" AND");
                }
                cond.Append("(");                                                               // put parens around this condition.
                // GroupId condition:
                if (groupIdCondition)
                {
                    if (m_GroupId.Count == 1)
                    {
                        cond.AppendFormat(" {0}={1}", strategyTable.GroupID, m_GroupId[0]);
                    }
                    else if (m_GroupId.Count > 1)
                    {
                        cond.AppendFormat(" {0} in ({1}", strategyTable.GroupID, m_GroupId[0]);
                        for (int n = 1; n < m_GroupId.Count; ++n)
                        {
                            cond.AppendFormat(",{0}", m_GroupId[n]);
                        }
                        cond.Append(")");
                    }
                    if (strategyIdCondition)                                                    // BOTH groupIds and stratIds were provided!
                    {
                        cond.Append(" OR");
                    }
                }
                if (strategyIdCondition)
                {
                    if (m_StrategyIds.Count == 1)
                    {
                        cond.AppendFormat(" {0}={1}", strategyTable.StrategyId, m_StrategyIds[0]);
                    }
                    else if (m_StrategyIds.Count > 1)
                    {
                        cond.AppendFormat(" {0} in ({1}", strategyTable.StrategyId, m_StrategyIds[0]);
                        for (int n = 1; n < m_StrategyIds.Count; ++n)
                        {
                            cond.AppendFormat(",{0}", m_StrategyIds[n]);
                        }
                        cond.Append(")");
                    }
                }
                cond.Append(")");                                                               // put parens around this condition.
            }

            // Now append them together.
            if (cond.Length > 0)
            {
                query.AppendFormat(" WHERE{0}", cond.ToString());
            }
            query.Append(";");
            return(query.ToString());
        }// GetQuery()