Exemple #1
0
        public static EasyBaseColumn COLLECT(EasyBaseColumn column, object result, int index, object value, bool condition)
        {
            if (result == null && value != null)
            {
                if (value.GetType() == typeof(int))
                {
                    result = new EasyIntColumn();
                }
                else if (value.GetType() == typeof(string))
                {
                    result = new EasyStringColumn();
                }
                else if (value.GetType() == typeof(bool))
                {
                    result = new EasyBoolColumn();
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            if (result == null)
            {
                return(null);
            }

            EasyBaseColumn b = (EasyBaseColumn)result;

            //if (condition) deðiþtirme!!!
            b.Insert(value);

            return(b);
        }
Exemple #2
0
 public void Delete(EasyTable table, EasyBaseColumn condition)
 {
     if (condition is EasyBoolColumn)
     {
         EasyBoolColumn b = (EasyBoolColumn)condition;
         int            l = b.GetRowCount();
         for (int i = 0; i < l; i++)
         {
             if (b.Values[i])
             {
                 table.Delete(i, Transaction);
             }
         }
     }
     else if (condition is EasyIntColumn)
     {
         EasyIntColumn iCol = (EasyIntColumn)condition;
         int           l    = iCol.GetRowCount();
         for (int i = 0; i < l; i++)
         {
             table.Delete(iCol.Values[i], Transaction);
         }
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Exemple #3
0
 public void Update(EasyTable table, EasyBaseColumn condition, KeyValuePair <string, object>[] values)
 {
     if (condition is EasyBoolColumn)
     {
         EasyBoolColumn b = (EasyBoolColumn)condition;
         int            l = b.GetRowCount();
         for (int i = 0; i < l; i++)
         {
             if (b.Values[i])
             {
                 table.Update(i, values, Transaction);
             }
         }
     }
     else if (condition is EasyIntColumn)
     {
         EasyIntColumn iCol = (EasyIntColumn)condition;
         int           l    = iCol.GetRowCount();
         for (int i = 0; i < l; i++)
         {
             table.Update(iCol.Values[i], values, Transaction);
         }
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Exemple #4
0
        /// <summary>
        /// Boolean Index Array
        /// </summary>
        public static EasyBoolColumn BI(EasyBaseColumn column, object result, int index, object value, bool condition)
        {
            if (result == null)
            {
                result = new EasyBoolColumn();
            }
            EasyBoolColumn b = (EasyBoolColumn)result;

            if (condition)
            {
                b.Values.Add(true);
            }
            else
            {
                b.Values.Add(false);
            }

            return(b);
        }
Exemple #5
0
        public EasyTable CreateTableStructure(string tablename, List <CreateField> columns, uint useTableId, uint[] useColumnId)
        {
            if (useTableId == 0)
            {
                tableId++;
                useTableId = tableId;
            }

            EasyTable table = new EasyTable()
            {
                Id = useTableId, Server = this
            };

            table.Name = tablename;
            int i = 0;

            foreach (CreateField column in columns)
            {
                uint id = 0;
                if (useColumnId == null)
                {
                    columnId++;
                    id = columnId;
                }
                else
                {
                    id = useColumnId[i];
                }
                i++;

                EasyBaseColumn col = null;
                if (column.FieldType == typeof(string))
                {
                    col = new EasyStringColumn()
                    {
                        Id = id
                    }
                }
                ;

                else if (column.FieldType == typeof(int))
                {
                    col = new EasyIntColumn()
                    {
                        Id = id
                    }
                }
                ;

                else if (column.FieldType == typeof(uint))
                {
                    col = new EasyUIntColumn()
                    {
                        Id = id
                    }
                }
                ;

                else if (column.FieldType == typeof(bool))
                {
                    col = new EasyBoolColumn()
                    {
                        Id = id
                    }
                }
                ;

                else if (column.FieldType == typeof(decimal))
                {
                    col = new EasyDecimalColumn()
                    {
                        Id = id
                    }
                }
                ;
                else
                {
                    throw new Exception("Unknown column type! " + column.FieldType);
                }

                col.Name       = column.Name;
                col.IsIdentity = column.IsIdentity;
                table.AddColumn(col);
            }

            Tables.Add(table);

            return(table);
        }
Exemple #6
0
        public DataTable Select(string tablename, List <string> fields, List <string> groupFields, WhereDelegate where)
        {
            if (groupFields != null && groupFields.Count == 0)
            {
                groupFields = null;
            }

            EasyTable table = FindTable(tablename);

            EasyBoolColumn rows = null;

            if (where != null)
            {
                rows = where ();
                //rows = (EasyBoolColumn)rows.Custom("&", table.RowColumn, EasyBaseColumn.COLLECT);
            }

            DataTable dt = new DataTable();
            //List<EasyBaseColumn> selectedFields = new List<EasyBaseColumn>();
            Dictionary <string, EasyBaseColumn> selectedFields = new Dictionary <string, EasyBaseColumn>();

            foreach (string field in fields)
            {
                if (field != "*")
                {
                    EasyBaseColumn column = null;
                    if (SqlParser.IsId(field))
                    {
                        column = table.FindColumn(field);
                        //selectedFields.Add(column);
                        selectedFields[field] = column;
                        dt.Columns.Add(field, column.GetColumnType());
                    }
                    else
                    {
                        List <string> t = SqlParser.Tokenize(field);
                        column = (EasyBaseColumn)ExecuteExpression(table, t);

                        //selectedFields.Add(column);
                        selectedFields[field] = column;
                        dt.Columns.Add(field, column.GetColumnType());
                    }
                }
                else
                {
                    foreach (var column in table.Columns)
                    {
                        //selectedFields.Add(column);
                        selectedFields[column.Name] = column;
                        dt.Columns.Add(column.Name, column.GetColumnType());
                    }
                }
            }

            //if (rows != null)
            // {
            int k        = 0;
            int rowCount = 0;

            foreach (EasyBaseColumn column in selectedFields.Values)
            {
                rowCount = column.GetRowCount();
                break;
            }
            Hashtable previousValues = new Hashtable();

            for (int i = 0; i < rowCount; i++)
            {
                if (rows != null && !rows.Values[i])
                {
                    continue;
                }
                if (table.RowColumn.Values[i] == 0)
                {
                    continue;
                }

                int j = 0;

                bool group = false;
                if (groupFields != null)
                {
                    group = true;
                    foreach (string groupField in groupFields)
                    {
                        if (k > 0)
                        {
                            object val = selectedFields[groupField].GetValue(i);
                            if (!selectedFields[groupField].EQ(val, previousValues[groupField]))
                            {
                                group = false;
                                previousValues[groupField] = val;
                            }
                        }
                        else
                        {
                            group = false;
                            previousValues[groupField] = selectedFields[groupField].GetValue(i);
                        }
                    }
                }
                if (group)
                {
                    continue;
                }

                dt.Rows.Add();
                foreach (EasyBaseColumn column in selectedFields.Values)
                {
                    dt.Rows[k][j] = column.GetValue(i);
                    j++;
                }
                k++;
            }
            //}
            //else
            //{
            //    int k = 0;
            //    int rowCount = 0;
            //    foreach (EasyBaseColumn column in selectedFields.Values)
            //    {
            //        rowCount = column.GetRowCount();
            //        break;
            //    }
            //    for (int i = 0; i < rowCount; i++)
            //    {
            //        if (table.RowColumn.Values[i] == 0) continue;

            //        dt.Rows.Add();
            //        int j = 0;
            //        foreach (EasyBaseColumn column in selectedFields.Values)
            //        {
            //            dt.Rows[k][j] = column.GetValue(i);
            //            j++;
            //        }
            //        k++;
            //    }
            //}

            return(dt);
        }