예제 #1
0
        /// <summary>
        /// For creation after "build for selection GUI"
        /// </summary>
        /// <param name="pax"></param>
        /// <param name="langs"></param>
        /// <param name="selections"></param>
        /// <param name="pxsqlMeta"></param>
        public PxsQuery(PCAxis.Paxiom.PXMeta pax, StringCollection langs, PCAxis.Paxiom.Selection[] selections, InfoFromPxSqlMeta2PxsQuery pxsqlMeta)
        {
            init1();


            #region this.Information
            //this.Information.CreatedDate = DateTime.Now;
            //skal bruke pax.Meta.CreationDate men hva er formatet til denne stringen?
            #endregion this.Information


            #region this.Query

            List <string> theLangs = new List <string>();
            foreach (string aLang in langs)
            {
                theLangs.Add(aLang);
            }


            this.setLangs(theLangs);

            //this.Query.TableSource = pax.TableID; // eller Matrix
            this.Query.TableSource = pax.MainTable;// changed. reqtest bug 325/339



            List <PQVariable> tmpPxsVars = new List <PQVariable>();


            foreach (Variable var in pax.Variables)
            {
                Selection correspondingSelection = null;
                foreach (Selection sel in selections)
                {
                    if (sel.VariableCode.Equals(var.Code))
                    {
                        correspondingSelection = sel;
                    }
                }



                if (var.IsContentVariable || var.Code.Equals("CONTENTSCODE") || var.IsTime || var.Code.Equals("TID") || var.Code.Equals("Tid"))
                {
                    List <BasicValueType> tmpList = new List <BasicValueType>();

                    int sortOrder = 1;

                    foreach (string valCode in correspondingSelection.ValueCodes)
                    {
                        if (var.IsContentVariable || var.Code.Equals("CONTENTSCODE")) // new piv
                        {
                            string contents = var.Values.GetByCode(valCode).ContentInfo.RefrenceID;
                            tmpList.Add(new BasicValueType(contents, sortOrder++));
                        }
                        else
                        {
                            tmpList.Add(new BasicValueType(valCode, sortOrder++));
                        }
                    }

                    if (var.IsContentVariable || var.Code.Equals("CONTENTSCODE"))
                    {
                        this.Query.Contents.code = var.Code;
                        //

                        //
                        this.Query.Contents.Content = tmpList.ToArray();
                    }
                    else
                    {
                        //pax vet bare nok til å lage timeoption 0 :-<
                        #region this.Query.Time
                        this.Query.Time.code       = var.Code;
                        this.Query.Time.TimeOption = TimeTypeTimeOption.Item0;

                        TimeTypeTimeValues tttv = new TimeTypeTimeValues();
                        tttv.TimeValue       = tmpList.ToArray();
                        this.Query.Time.Item = tttv;

                        this.Query.Time.TimeVal = var.TimeValue;//??
                        #endregion this.Query.Time
                    }
                }
                else     //classification
                {
                    #region preparing for this.Query.Variables
                    PQVariable tmpPxsVar = new PQVariable();
                    tmpPxsVar.code = var.Code;

                    //på tynn is her:

                    tmpPxsVar.Aggregation = PQVariableAggregation.N;

                    string selectedValueset = pxsqlMeta.GetSelectedValuesetId(var.Code);


                    string currentGrouping = pxsqlMeta.GetCurrentGroupingId(var.Code);


                    //
                    // string currentGrouping = var.CurrentGrouping; will get trouble for pxs4selection
                    // with a grouping, since it is not an "applied grouping", but more of a "backgroud grouping"


                    if (!String.IsNullOrEmpty(currentGrouping))
                    {
                        tmpPxsVar.Aggregation = PQVariableAggregation.G;
                        tmpPxsVar.StructureId = currentGrouping;
                        log.Debug(currentGrouping);
                        //} else if ( (! String.IsNullOrEmpty(selectedValueset)) &&
                        //    selectedValueset != PXSqlKeywords.FICTIONAL_ID_ALLVALUESETS) {
                        //        tmpPxsVar.StructureId = pxsqlMeta.Variables[var.Code].SelectedValueset;
                        //        tmpPxsVar.Aggregation = PQVariableAggregation.V;
                        //    // denne skulle vel bort?
                    }
                    //skip variables which does not have codes in Selection object
                    if (correspondingSelection == null || correspondingSelection.ValueCodes.Count == 0)
                    {
                        if (pxsqlMeta.GetSelectedValuesetId(var.Code) == null || (pxsqlMeta.GetSelectedValuesetId(var.Code) == PXSqlKeywords.FICTIONAL_ID_ALLVALUESETS && String.IsNullOrEmpty(currentGrouping))) // added to save info about selected valueset.
                        {
                            continue;
                        }
                    }

                    //Hmm: hva skal gjelde: paxiom eller pxs?
                    //Hmm2: ved endring av kode/text i grensesntitt, bør det kjøres en applyCodeText noe som fører til at neste linje kan slettes og opsjon fra paxiom brukes
                    //tmpPxsVar.PresTextOption = "Both";


                    tmpPxsVar.Values       = new PQVariableValues();
                    tmpPxsVar.Values.Items = new ValueTypeWithGroup[correspondingSelection.ValueCodes.Count];

                    for (int n = 0; n < tmpPxsVar.Values.Items.Length; n++)
                    {
                        tmpPxsVar.Values.Items[n] = new ValueTypeWithGroup(correspondingSelection.ValueCodes[n], n + 1);
                    }

                    tmpPxsVar.SelectedValueset = pxsqlMeta.GetSelectedValuesetId(var.Code); // To fix problem with missing valueset info when more than two variabeles with multiple valuesets. e.g no subtable is set.
                    tmpPxsVars.Add(tmpPxsVar);
                    #endregion preparing for this.Query.Variables
                }
            }

            this.Query.Variables = tmpPxsVars.ToArray();
            #endregion this.Query

            #region this.Presentation
            this.Presentation = new PresentationType();
            if (pax.Stub.Count > 0)
            {
                this.Presentation.Stub = new AxisType[pax.Stub.Count];
                for (int n = 0; n < pax.Stub.Count; n++)
                {
                    this.Presentation.Stub[n] = new AxisType(pax.Stub[n].Code, n);
                }
            }

            if (pax.Heading.Count > 0)
            {
                this.Presentation.Heading = new AxisType[pax.Heading.Count];
                for (int n = 0; n < pax.Heading.Count; n++)
                {
                    this.Presentation.Heading[n] = new AxisType(pax.Heading[n].Code, n);
                }
            }

            #endregion this.Presentation
        }
예제 #2
0
        // call this when there are no more segments
        // it converts lists to arrays and adds them to the object
        // (The lists are used when parsing since arrays cannot grow dynamically)
        //recodes data.Query.Time.TimeOption "1" to "2"
        private void postParse(FlatFileReaderHelper helper, string resultLanguage)
        {
            bool[] isElim    = new bool[helper.no_vars];
            int    elimCount = 0;

            // Traverses the variables one by one
            for (int n = 0; n < helper.no_vars; n++)
            {
                isElim[n] = helper.variableValues[n].Count < 1; // Common to all elimination: No values!
                if (isElim[n])
                {
                    elimCount++;
                }
                log.Debug("isElim=" + isElim[n] + " code" + helper.tmpVariable[n].code);
                //adds any group values

                // For each value vt belonging to the current variable n do ....
                foreach (ValueTypeWithGroup vt in helper.variableValues[n])
                {
                    // Checks if the current value code vt.code has a list of group codes associated with it
                    if (helper.groupsValuesByValueCode[n].ContainsKey(vt.code))
                    {
                        // If so, then create a temporary GroupValueType tmp to hold the list of group codes
                        List <GroupValueType> tmp = helper.groupsValuesByValueCode[n][vt.code];

                        // Creates an object of type ValueTypeWithGroupGroup and transfers the list of group codes to it
                        vt.Group            = new ValueTypeWithGroupGroup();
                        vt.Group.GroupValue = tmp.ToArray();
                        // Checks (on the sort order) if there is a ValueText (Group text) attached to any of the values
                        if (helper.groupTextByValueSortOrder[n].ContainsKey(vt.sortOrder))
                        {
                            // text er bare for grupper som kommer fra filer, hva med språk?
                            StringLangType[] tmpSLT = new StringLangType[1];
                            tmpSLT[0]       = new StringLangType();
                            tmpSLT[0].Value = helper.groupTextByValueSortOrder[n][vt.sortOrder];
                            if (helper.langInFile == null)
                            {
                                tmpSLT[0].lang = resultLanguage;
                                log.Warn("Found text but no language. Using " + resultLanguage);
                            }
                            else
                            {
                                tmpSLT[0].lang = helper.langInFile;
                            }
                            vt.Group.GroupText = tmpSLT;
                        }
                    }
                }

                // helper.tmpVariable[n].Values is an array of pointers to ValueTypeWithGroup,
                // which means that it is similar to helper.variableValues (which is a list)
                helper.tmpVariable[n].Values.Items = helper.variableValues[n].ToArray();
            }

            if ((int)this.Query.Time.TimeOption == 0)
            {
                TimeTypeTimeValues tttv = new TimeTypeTimeValues();
                tttv.TimeValue       = helper.timeValues.ToArray();
                this.Query.Time.Item = tttv;
            }
            else if ((int)this.Query.Time.TimeOption == 1)
            {
                this.Query.Time.TimeOption = (TimeTypeTimeOption)2;
                int noOfValues = 1;
                this.Query.Time.Item = noOfValues;
            }

            this.Query.Contents.Content = helper.contentValues.ToArray();

            if (helper.menuSelList.Count > 0)
            {
                this.Information.Menu = helper.menuSelList.ToArray();
            }

            #region set Language

            myLanguageType[] tmpMyLang = new myLanguageType[1];
            tmpMyLang[0] = new myLanguageType();

            if (helper.langInFile == null)
            {
                tmpMyLang[0].Value = resultLanguage;
                log.Warn(" no language. Using " + resultLanguage);
            }
            else
            {
                tmpMyLang[0].Value = helper.langInFile;
            }

            this.Query.Languages.Items = tmpMyLang;

            #endregion set Language

            // Allocating an array of PQVariable under QueryType.Query.Variables
            this.Query.Variables = new PQVariable[helper.no_vars - elimCount];
            //hva når det er 0

            //All [] helpers has entries for the eliminated. These must be skipped.



            #region fix stub heading
            // Hva med de som de eliminert??

            int             stub_counter  = 0; //-1
            int             head_counter  = 0; //-1
            List <AxisType> headList      = new List <AxisType>();
            List <AxisType> stubList      = new List <AxisType>();
            int             outVarCounter = 0;

            // Traverses the variables found in the pxs file
            #region for loop
            for (int n = 1; n <= helper.no_vars; n++)
            {
                if (isElim[n - 1])
                {
                    continue;  // If the variable is eliminated, then skip it
                }
                this.Query.Variables[outVarCounter] = helper.tmpVariable[n - 1];
                outVarCounter++;



                string code = helper.tmpVariable[n - 1].code;
                // helper.no_vars_before_heading show
                if (n <= helper.no_vars_before_heading)
                {
                    // stub_counter++;
                    stubList.Add(new AxisType(code, stub_counter++));
                }
                else
                {
                    // head_counter++;
                    headList.Add(new AxisType(code, head_counter++));
                }


                if (n == helper.no_vars_before_time)    //Time
                {
                    string timeCode = this.Query.Time.code;
                    if (n < helper.no_vars_before_heading)
                    {
                        stubList.Add(new AxisType(timeCode, stub_counter++));
                    }
                    else
                    {
                        headList.Add(new AxisType(timeCode, head_counter++));
                    }
                }
            }
            #endregion for loop



            headList.Add(new AxisType(this.Query.Contents.code, head_counter++));


            this.Presentation = new PresentationType();
            if (stubList.Count > 0)
            {
                this.Presentation.Stub = stubList.ToArray();
            }
            if (headList.Count > 0)
            {
                this.Presentation.Heading = headList.ToArray();
            }

            #endregion fix stub heading
        }