Exemple #1
0
        /// <summary>
        /// get object where
        /// </summary>
        /// <param name="Object">指定的条件生成对象</param>
        public override String GetWhere(TableBase Object)
        {
            if (!string.IsNullOrEmpty(Object.TableCondition.Where))
            {
                return(" WHERE " + Object.TableCondition.Where);
            }
            //where to object
            //if (Object.Condition.WhereObject != null) return new TableToSQL(Object.Condition.WhereObject, Factory, parameter).GetWhere;
            //object property
            StringBuilder tmp   = new StringBuilder();
            string        split = Object.TableCondition.WhereSplit + " ";

            Dictionary <string, object> .Enumerator etor = Object.GetEnumerator();
            //Type type;
            while (etor.MoveNext())
            {
                tmp.Append(split);

                if (etor.Current.Value != null && etor.Current.Value.GetType() == dateType)
                {
                    tmp.AppendFormat("{0}=#{1}#", etor.Current.Key, etor.Current.Value);
                }
                else
                {
                    tmp.AppendFormat("{0}={1}{0}", etor.Current.Key, Factory.GetParameterSplitChar);
                    parameter.Add(Factory.CreateParameter(etor.Current.Key, etor.Current.Value));
                }
            }
            if (tmp.Length > 0)
            {
                return(" WHERE " + tmp.Remove(0, split.Length).ToString());
            }
            return("");
        }
Exemple #2
0
        /// <summary>
        /// get object where
        /// </summary>
        /// <param name="Object">指定的条件生成对象</param>
        public virtual String GetWhere(TableBase Object)
        {
            if (!string.IsNullOrEmpty(Object.TableCondition.Where))
            {
                return(" WHERE " + Object.TableCondition.Where);
            }
            //where to object
            //if (Object.Condition.WhereObject != null) return new TableToSQL(Object.Condition.WhereObject, Factory, parameter).GetWhere;
            //object property
            StringBuilder tmp   = new StringBuilder();
            string        split = Object.TableCondition.WhereSplit + " ";

            Dictionary <string, object> .Enumerator etor = Object.GetEnumerator();
            //Type type;
            while (etor.MoveNext())
            {
                tmp.Append(split);
                tmp.AppendFormat("{0}={1}{0}", etor.Current.Key, Factory.GetParameterSplitChar);
                parameter.Add(Factory.CreateParameter(etor.Current.Key, etor.Current.Value));

                /*//type = etor.Current.Value.GetType();
                 * if (type == typeof(int) || type == typeof(bool))
                 *  tmp.AppendFormat("{0}={1}", etor.Current.Key, etor.Current.Value);
                 * else if (etor.Current.Value == null || etor.Current.Value == DBNull.Value)
                 *  tmp.AppendFormat("{0}=NULL", etor.Current.Key);
                 * else
                 *  tmp.AppendFormat("{0}='{1}'", etor.Current.Key, SQLUtility.Replace(etor.Current.Value.ToString()));*/
            }
            if (tmp.Length > 0)
            {
                return(" WHERE " + tmp.Remove(0, split.Length).ToString());
            }
            return("");
        }
Exemple #3
0
        /// <summary>
        /// 根据对象创建参数列表,使用<see cref="GetParameterSplitChar"/>所指定的参数前缀
        /// </summary>
        /// <param name="obj">对象</param>
        protected virtual IDbDataParameter[] CreateParameter(TableBase obj)
        {
            //object property
            Dictionary <string, object> .Enumerator etor = obj.GetEnumerator();
            List <IDbDataParameter> list = new List <IDbDataParameter>();

            while (etor.MoveNext())
            {
                list.Add(CreateParameter(GetParameterSplitChar + etor.Current.Key, etor.Current.Value));
            }
            //other parames
            if (null != obj.TableCondition.Parameters)
            {
                list.AddRange(obj.TableCondition.Parameters);
            }

            //return out
            return(list.ToArray());
        }