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); } }
private State.Field.DateField GetDateField(DateadvancefunctionContext df) { State.Field.DateField.FunctionType ft = getDateFunction(df.DATEUDF().GetText()); if (ft == State.Field.DateField.FunctionType.DATEDIFF) { var fv = df.children[2].GetText().Split(','); return(new State.Field.DateField(fv[0], "") { CompareColumn = fv[1], Function = ft, }); } else if (ft == State.Field.DateField.FunctionType.DATEADD) { var fv = df.children[2].GetText().Split(','); return(new State.Field.DateField(fv[0], "") { NumberOfDays = Convert.ToInt32(fv[1]), Function = ft, }); } else if (ft == State.Field.DateField.FunctionType.DATEFORMAT) { var fv = df.children[2].GetText().Split(','); return(new State.Field.DateField(fv[0], "") { Format = fv[1], Function = ft, }); } else if (ft == State.Field.DateField.FunctionType.BETWEENMONTH) { var fv = df.children[2].GetText().Split(','); return(new State.Field.DateField(fv[0], "") { CompareColumn = fv[1], Function = ft, }); } else if (ft == State.Field.DateField.FunctionType.ADDMONTH) { var fv = df.children[2].GetText().Split(','); return(new State.Field.DateField(fv[0], "") { NumberOfMonths = Convert.ToInt32(fv[1]), Function = ft, }); } else if (ft == State.Field.DateField.FunctionType.NEXT) { var fv = df.children[2].GetText().Split(','); return(new State.Field.DateField(fv[0], "") { Format = fv[1], Function = ft, }); } else if (ft == State.Field.DateField.FunctionType.TODATE) { var fv = df.children[2].GetText().Split(','); return(new State.Field.DateField(fv[0], "") { Format = fv[1], Function = ft, }); } else if (ft == State.Field.DateField.FunctionType.TOTIME) { var fv = df.children[2].GetText().Split(','); return(new State.Field.DateField(fv[0], "") { Format = fv[1], Function = ft, }); } else { throw new Exception("Undefined function in date"); } }