private void SetSearch(FilterconditionContext filter, string name, string varName)
 {
     if (filter != null)
     {
         var dq = new DataCube(name, DataStatement.SEARCH, varName);
         ConditionContext condition = filter.condition();
         var search = new State.Search(condition.children[0].GetText(), condition.children[1].GetText(), condition.children[2].GetText());
         dq.SearchStatement = (search);
         DataCubes.Add(dq);
     }
 }
 private void SetGroupby(GroupbyContext groupby, string name, string varName)
 {
     if (groupby != null)
     {
         var                    dq              = new DataCube(name, DataStatement.GROUPBY, varName);
         FieldsContext          fields          = groupby.fields();
         FilterconditionContext Filtercondition = groupby.filtercondition();
         SortstatementContext   sortStatement   = groupby.sortstatement();
         AggContext             agg             = groupby.agg();
         if (fields != null)
         {
             string[] s = fields.GetText().Split(',');
             for (int i = 0; i < s.Length; i++)
             {
                 dq.GroupByStatement.AddField(new State.DataField(s[i], s[i]));
             }
         }
         if (agg != null)
         {
             string[] s = agg.GetText().Split(',');
             for (int i = 0; i < s.Length; i++)
             {
                 string[] f = s[i].Split('.');
                 var      a = new State.AggregateField(f[0], f[0])
                 {
                     AggregateType = f[1]
                 };
                 dq.GroupByStatement.AddAgg(a);
             }
         }
         if (Filtercondition != null)
         {
             ConditionContext condition = Filtercondition.condition();
             var search = new State.Search(condition.children[0].GetText(), condition.children[1].GetText(), condition.children[2].GetText());
             dq.SelectStatement.AddCondition(search);
         }
         if (sortStatement != null)
         {
             OrderContext order = sortStatement.order();
             dq.SelectStatement.AddOrder(new State.SortBy(order.ORDERBY()[0].GetText(), order.fields()[0].GetText()));
         }
         DataCubes.Add(dq);
     }
 }
        private void SetRollup(RollupContext rollup, string name, string varName)
        {
            var dq = new DataCube(name, DataStatement.ROLLUP, varName);

            if (rollup != null)
            {
                FilterconditionContext Filtercondition = rollup.filtercondition();
                SortstatementContext   sortStatement   = rollup.sortstatement();
                FieldsContext          fs      = rollup.fields();
                AggtypeContext         aggtype = rollup.aggtype();
                dq.RollupStatement = new State.Rollup()
                {
                    Aggregate = aggtype.GetText()
                };
                if (fs != null)
                {
                    string[] s = fs.GetText().Split(',');
                    for (int i = 0; i < s.Length; i++)
                    {
                        dq.RollupStatement.AddField(new State.DataField(s[i], s[i]));
                    }
                }
                if (Filtercondition != null)
                {
                    ConditionContext condition = Filtercondition.condition();
                    var search = new State.Search(condition.children[0].GetText(), condition.children[1].GetText(), condition.children[2].GetText());
                    dq.RollupStatement.AddCondition(search);
                }
                if (sortStatement != null)
                {
                    OrderContext order = sortStatement.order();
                    dq.RollupStatement.AddOrder(new State.SortBy(order.ORDERBY()[0].GetText(), order.fields()[0].GetText()));
                }
                DataCubes.Add(dq);
            }
        }
 private void SetSelect(SelectContext select, string name, string varName)
 {
     if (select != null)
     {
         var                    dq              = new DataCube(name, DataStatement.SELECT, varName);
         FieldsContext          fields          = select.fields();
         FilterconditionContext Filtercondition = select.filtercondition();
         SortstatementContext   sortStatement   = select.sortstatement();
         if (fields != null)
         {
             StringltrContext[] fieldStrings = fields.stringltr();
             if (fieldStrings != null)
             {
                 foreach (StringltrContext sc in fieldStrings)
                 {
                     if (sc.strings() != null)
                     {
                         var ss = sc.strings().GetText();
                         if (ss.IndexOf(":") > 0)
                         {
                             var sf = ss.Split(':');
                             dq.SelectStatement.AddField(new State.Field.StringField(sf[0], sf[1]));
                         }
                         else
                         {
                             dq.SelectStatement.AddField(new State.Field.StringField(ss, ss));
                         }
                     }
                     else if (sc.datefunction() != null)
                     {
                         DatefunctionContext df = sc.datefunction();
                         dq.SelectStatement.AddField(new State.Field.DateField(df.WORD().GetText(), sc.WORD().GetText())
                         {
                             Function = getDateFunction(df.DATEFUNCTION().GetText())
                         });
                     }
                     else if (sc.dateadvancefunction() != null)
                     {
                         DateadvancefunctionContext df = sc.dateadvancefunction();
                         var dfield = GetDateField(df);
                         dfield.AliasName = sc.WORD().GetText();
                         dq.SelectStatement.AddField(dfield);
                     }
                     else if (sc.numberfunction() != null)
                     {
                         NumberfunctionContext nf = sc.numberfunction();
                         State.Field.NumberField.FunctionType nft = getNumFunction(nf.NUMBERUDF().GetText());
                         string fm = "";
                         if (nft == State.Field.NumberField.FunctionType.NUMBERFORMAT || nft == State.Field.NumberField.FunctionType.ROUND)
                         {
                             //  fm = nf.dataformat().INT().GetText().ToString();
                         }
                         dq.SelectStatement.AddField(new State.Field.NumberField(nf.WORD().GetText(), sc.WORD().GetText())
                         {
                             Function = getNumFunction(nf.NUMBERUDF().GetText()), Format = fm
                         });
                     }
                     else if (sc.numberformat() != null)
                     {
                         NumberformatContext nf = sc.numberformat();
                         State.Field.NumberField.FunctionType nft = getNumFunction(nf.NUMBERUDF().GetText());
                         string fm = "";
                         if (nft == State.Field.NumberField.FunctionType.NUMBERFORMAT || nft == State.Field.NumberField.FunctionType.ROUND)
                         {
                             fm = nf.INT().GetText().ToString();
                         }
                         dq.SelectStatement.AddField(new State.Field.NumberField(nf.WORD().GetText(), sc.WORD().GetText())
                         {
                             Function = getNumFunction(nf.NUMBERUDF().GetText()), Format = fm
                         });
                     }
                     else if (sc.stringfunction() != null)
                     {
                         StringfunctionContext df = sc.stringfunction();
                         State.Field.StringField.FunctionType nft = getStringFunction(df.STRINGUDF().GetText());
                         //string fm = "";
                         //if (nft == State.Field.StringField.FunctionType.FORMAT)
                         //{
                         //    fm = df.dataformat().INT().GetText().ToString();
                         //}
                         dq.SelectStatement.AddField(new State.Field.StringField(df.WORD().GetText(), sc.WORD().GetText())
                         {
                             Function = getStringFunction(df.STRINGUDF().GetText()), Format = ""
                         });
                     }
                     else if (sc.stringformat() != null)
                     {
                         StringformatContext df = sc.stringformat();
                         State.Field.StringField.FunctionType nft = State.Field.StringField.FunctionType.FORMAT;
                         string fm = "";
                         if (nft == State.Field.StringField.FunctionType.FORMAT)
                         {
                             fm = df.TEXT().GetText();
                         }
                         dq.SelectStatement.AddField(new State.Field.StringField(df.WORD().GetText(), sc.WORD().GetText())
                         {
                             Function = nft, Format = fm
                         });
                     }
                 }
             }
         }
         if (Filtercondition != null)
         {
             ConditionContext condition = Filtercondition.condition();
             var search = new State.Search(condition.children[0].GetText(), condition.children[1].GetText(), condition.children[2].GetText());
             dq.SelectStatement.AddCondition(search);
         }
         if (sortStatement != null)
         {
             OrderContext order = sortStatement.order();
             dq.SelectStatement.AddOrder(new State.SortBy(order.ORDERBY()[0].GetText(), order.fields()[0].GetText()));
         }
         DataCubes.Add(dq);
     }
 }