Exemplo n.º 1
0
        public QBetween(object val1 = null, object val2 = null, DBColumn column = null)
        {
            if (val1 is QItem)
            {
                value1 = (QItem)val1;
            }
            else if (val1 is DBColumn)
            {
                value1 = new QColumn((DBColumn)val1);
            }
            else if (val1 != null)
            {
                value1 = new QValue(val1, column);
            }

            if (val2 is QItem)
            {
                value2 = (QItem)val1;
            }
            else if (val2 is DBColumn)
            {
                value2 = new QColumn((DBColumn)val2);
            }
            else if (val2 != null)
            {
                value2 = new QValue(val2, column);
            }
        }
Exemplo n.º 2
0
        public override string Format(IDbCommand command = null)
        {
            var rez = new StringBuilder();

            rez.Append(type.ToString());
            rez.Append("(");
            QItem prev = null;

            foreach (var item in items)
            {
                if (!items.IsFirst(item) && !(item is QComparer) && !(prev is QComparer))
                {
                    rez.Append(", ");
                }
                rez.Append(item.Format(command));
                prev = item;
            }
            rez.Append(")");
            return(rez.ToString());
        }
Exemplo n.º 3
0
 public void SetValue(QItem value)
 {
     if (ValueLeft == null)
     {
         ValueLeft = value;
     }
     else if (ValueRight == null)
     {
         ValueRight = value;
     }
     else if (ValueRight is QBetween between)
     {
         if (between.Min == null)
         {
             between.Min = value;
         }
         else if (between.Max == null)
         {
             between.Max = value;
         }
     }
 }
Exemplo n.º 4
0
 public string FormatValue(QItem Value, IDbCommand command = null)
 {
     if (Value == null)
     {
         return(string.Empty);
     }
     if (Value is QQuery && ((QQuery)Value).Table != null)
     {
         QQuery squery = (QQuery)Value;
         if (squery.Columns.Count == 0)
         {
             squery.Columns.Add(new QColumn(squery.Table.PrimaryKey));
         }
         return("(" + squery.Format(command) + ")");
     }
     else if (Value is QExpression)
     {
         return("(" + Value.Format(command) + ")");
     }
     else
     {
         return(Value.Format(command));
     }
 }
Exemplo n.º 5
0
        public override object GetValue(DBItem row = null)
        {
            QItem item = items.Count == 0 ? null : items[0];

            switch (type)
            {
            case QFunctionType.lower:
                return(item.GetValue(row)?.ToString().ToLowerInvariant());

            case QFunctionType.upper:
                return(item.GetValue(row)?.ToString().ToUpperInvariant());

            case QFunctionType.initcap:
                return(Helper.ToInitcap(item.GetValue(row)?.ToString(), ' '));

            case QFunctionType.trim:
                return(item.GetValue(row)?.ToString().Trim());

            case QFunctionType.ltrim:
                return(item.GetValue(row)?.ToString().TrimStart());

            case QFunctionType.rtrim:
                return(item.GetValue(row)?.ToString().TrimEnd());

            case QFunctionType.getdate:
                return(DateTime.Now);

            case QFunctionType.concat:
                var sb = new StringBuilder();
                foreach (var parameter in items)
                {
                    sb.Append(parameter.GetValue(row));
                }
                return(sb.ToString());

            case QFunctionType.coalesce:
                foreach (var parameter in items)
                {
                    var value = parameter.GetValue(row);
                    if (value != null)
                    {
                        return(value);
                    }
                }
                return(null);

            case QFunctionType.convert:
            {
                var paramType = items[0] as QType;
                var column    = ((QColumn)items[1]).Column;
                var val       = row[column];

                if (paramType.Type == DBDataType.Date)
                {
                    if (val == DBNull.Value)
                    {
                        return(val);
                    }
                    else if (!(val is DateTime))
                    {
                        val = DateTime.Parse(val.ToString());
                    }
                    return(((DateTime)val).Date);
                }
                else if (paramType.Type == DBDataType.String)
                {
                    string temp = string.Empty;
                    if (val == DBNull.Value)
                    {
                        return(string.Empty);
                    }
                    else if (val is DateTime)
                    {
                        string format = "yyyy-MM-dd HH:mm:ss.fff";
                        if (items.Count == 3)
                        {
                            string f = items[2].Text;
                            if (f == "112")
                            {
                                format = "yyyyMMdd";
                            }
                            else if (f == "12")
                            {
                                format = "yyMMdd";
                            }
                            else if (f == "6")
                            {
                                format = "dd MMM yyyy";
                            }
                        }
                        temp = ((DateTime)val).ToString(format);
                    }
                    else
                    {
                        temp = DBSystem.FormatText(val);
                    }
                    if (paramType.Size > 0 && temp.Length > paramType.Size)
                    {
                        temp = temp.Substring(0, (int)paramType.Size);
                    }
                    return(temp);
                }
                else
                {
                }

                break;
            }

            case QFunctionType.parse:
            {
                var param = items[0].Text.Trim('\'');
                var local = items.Count > 3 ? System.Globalization.CultureInfo.GetCultureInfo(items[4].Text.Trim('\'')) : System.Globalization.CultureInfo.CurrentCulture;
                var t     = items[2] as QType;
                if (t.Type == DBDataType.Date || t.Type == DBDataType.DateTime)
                {
                    return(DateTime.Parse(param, local));
                }
                else if (t.Type == DBDataType.Decimal)
                {
                    return(decimal.Parse(param, local));
                }

                break;
            }

            case QFunctionType.datename:
            {
                var param  = items[0].Text;
                var column = ((QColumn)items[1]).Column;
                var val    = row[column];
                if (!(val is DateTime))
                {
                    val = DateTime.Parse(val.ToString());
                }
                return(((DateTime)val).ToString(param));
            }
            }
            return(null);
        }
Exemplo n.º 6
0
 public void Delete(QItem item)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
 public void Delete(QItem item)
 {
     Remove((T)item);
 }
Exemplo n.º 8
0
 public void Delete(QItem item)
 {
     Items.Delete(item);
 }
Exemplo n.º 9
0
        public override object GetValue(DBItem row = null)
        {
            QItem item = items.Count == 0 ? null : items[0];

            if (type == QFunctionType.lower)
            {
                return(item.GetValue(row).ToString().ToLowerInvariant());
            }
            if (type == QFunctionType.upper)
            {
                return(item.GetValue(row).ToString().ToUpperInvariant());
            }
            if (type == QFunctionType.getdate)
            {
                return(DateTime.Now);
            }
            if (type == QFunctionType.convert)
            {
                var param  = items[0] as QType;
                var column = ((QColumn)items[1]).Column;
                var val    = row[column];

                if (param.Type == DBDataType.Date)
                {
                    if (val == DBNull.Value)
                    {
                        return(val);
                    }
                    else if (!(val is DateTime))
                    {
                        val = DateTime.Parse(val.ToString());
                    }
                    return(((DateTime)val).Date);
                }
                else if (param.Type == DBDataType.String)
                {
                    string temp = string.Empty;
                    if (val == DBNull.Value)
                    {
                        return(string.Empty);
                    }
                    else if (val is DateTime)
                    {
                        string format = "yyyy-MM-dd HH:mm:ss.fff";
                        if (items.Count == 3)
                        {
                            string f = items[2].Text;
                            if (f == "112")
                            {
                                format = "yyyyMMdd";
                            }
                            else if (f == "12")
                            {
                                format = "yyMMdd";
                            }
                            else if (f == "6")
                            {
                                format = "dd MMM yyyy";
                            }
                        }
                        temp = ((DateTime)val).ToString(format);
                    }
                    else
                    {
                        temp = DBSystem.FormatText(val);
                    }
                    if (param.Size > 0 && temp.Length > param.Size)
                    {
                        temp = temp.Substring(0, (int)param.Size);
                    }
                    return(temp);
                }
                else
                {
                }
            }
            if (type == QFunctionType.parse)
            {
                var param = items[0].Text.Trim('\'');
                var local = items.Count > 3 ? System.Globalization.CultureInfo.GetCultureInfo(items[4].Text.Trim('\'')) : System.Globalization.CultureInfo.CurrentCulture;
                var t     = items[2] as QType;
                if (t.Type == DBDataType.Date || t.Type == DBDataType.DateTime)
                {
                    return(DateTime.Parse(param, local));
                }
                else if (t.Type == DBDataType.Decimal)
                {
                    return(decimal.Parse(param, local));
                }
            }
            if (type == QFunctionType.datename)
            {
                var param  = items[0].Text;
                var column = ((QColumn)items[1]).Column;
                var val    = row[column];
                if (!(val is DateTime))
                {
                    val = DateTime.Parse(val.ToString());
                }
                return(((DateTime)val).ToString(param));
            }
            return(null);
        }