Esempio n. 1
0
        private int CheckNCreateTotalSubgroupUnderLocation(string TotalSGText)
        {
            int RetVal = 0;

            DI6SubgroupInfo SGInfo = new DI6SubgroupInfo();

            DI6SubgroupBuilder     SGBuilder     = new DI6SubgroupBuilder(this.DBConnection, this.DBQueries);
            DI6SubgroupTypeBuilder SGTypeBuilder = new DI6SubgroupTypeBuilder(this.DBConnection, this.DBQueries);

            SGInfo.Name           = TotalSGText;
            SGInfo.Type           = this.LocationTypeInfo.Nid;
            SGInfo.DISubgroupType = this.LocationTypeInfo;

            RetVal = SGBuilder.CheckNCreateSubgroup(SGInfo);

            return(RetVal);
        }
Esempio n. 2
0
        /// <summary>
        /// Checks and updates the SubgroupVal text for the given SubgroupValNIds
        /// </summary>
        /// <param name="SubgroupValNIds"></param>
        public void CheckNUpdateSubgroupValText(int SubgroupValNId, DI6SubgroupValBuilder SGValBuilder, DIQueries TempQueries)
        {
            string SqlQuery                        = string.Empty;
            string SubgroupNids                    = string.Empty;
            string DI5SubgroupValText              = string.Empty;
            string NewSubgroupValText              = string.Empty;
            string NewSubgroupValTextWTotal        = string.Empty;
            string NewSubgroupValTextWTotalNPrefix = string.Empty;

            string TotalTextValue = string.Empty;

            int  TotalNId             = 0;
            bool IsTotalSGFound       = false;
            bool IsSubgroupValInvalid = true;

            DI6SubgroupValInfo SGValInfo;

            DI6SubgroupBuilder SGBuilder;
            DI6SubgroupInfo    SGInfo = new DI6SubgroupInfo();



            bool   IsLocationSubgroupExistsInSubgroup = false;
            string LocationSubgroupName = string.Empty;
            int    LocationSubgroupNId  = 0;
            int    NewSubgroupNId       = 0;

            try
            {
                // get total text value for the curent langauge
                TotalTextValue = this.GetTotalTextString(TempQueries.LanguageCode);


                SGBuilder = new DI6SubgroupBuilder(this.DBConnection, TempQueries);

                // Step1: get SubgroupVal info
                SGValInfo = SGValBuilder.GetSubgroupValInfo(FilterFieldType.NId, SubgroupValNId.ToString());
                //NewSubgroupValText

                if (SGValInfo != null)
                {
                    DI5SubgroupValText = DICommon.RemoveQuotes(Convert.ToString(SGValInfo.Name));


                    // Get subgroup Nids and check location subgroup exists in the template/databse.
                    foreach (DI6SubgroupInfo DimensionValue in SGValInfo.Dimensions)
                    {
                        if (!string.IsNullOrEmpty(SubgroupNids))
                        {
                            SubgroupNids += ",";
                        }
                        SubgroupNids += DimensionValue.Nid;

                        if (DimensionValue.Nid == 0 || DimensionValue.DISubgroupType == null)
                        {
                            // subgroup missing in DI5 but relationship of that subgroup exists in Subgroup_VAls table
                        }
                        else
                        {
                            if (DimensionValue.DISubgroupType.Order == 1) // 1 order is for location in DI5 DB
                            {
                                IsLocationSubgroupExistsInSubgroup = true;
                                LocationSubgroupName = DimensionValue.Name;
                                LocationSubgroupNId  = DimensionValue.Nid;
                            }
                        }
                    }
                }
                // Step3: Check and update SubgroupVal text
                if (!string.IsNullOrEmpty(SubgroupNids))
                {
                    // Step 3.1: Get New subgroup val text
                    NewSubgroupValText = DICommon.RemoveQuotes(SGValBuilder.CreateSubgroupValTextBySubgroupNids(SubgroupNids));
                }
                // step 3.2: compare New subgroup Val text with DI5SubgroupVal text
                // step 3.2.1: compare Normal text value
                if (NewSubgroupValText.ToLower() != DI5SubgroupValText.ToLower())
                {
                    // step 3.2.2: if text doesnot match then compare the subgroup val with Total
                    NewSubgroupValTextWTotal = TotalTextValue + " " + NewSubgroupValText;

                    if (NewSubgroupValTextWTotal.ToLower() == DI5SubgroupValText.ToLower())
                    {
                        IsTotalSGFound = true;
                    }
                    else
                    {
                        // step 3.2.3: if text still doesnot match then compare the subgroup val with Total and prefix (#)
                        NewSubgroupValTextWTotalNPrefix = Constants.PrefixForNewValue + TotalTextValue + " " + NewSubgroupValText;

                        if (NewSubgroupValTextWTotalNPrefix.ToLower() == DI5SubgroupValText.ToLower())
                        {
                            TotalTextValue = Constants.PrefixForNewValue + TotalTextValue;
                            IsTotalSGFound = true;
                        }
                    }



                    // if New subgroup text matched with DI5 subgroup text
                    if (IsTotalSGFound)
                    {
                        // Check New DI6 subgrop text has Location subgroup
                        //      If location subgroup dimension exists,
                        if (IsLocationSubgroupExistsInSubgroup)
                        {
                            //          Delete the relationship of subgroup with the location subgroup
                            SGValBuilder.DeleteSubgroupValRelations(SubgroupValNId, LocationSubgroupNId.ToString());

                            //          Create new subgroup under location where subgroup value is equal to "Total" + available value of location subgroup dimension
                            SGInfo = new DI6SubgroupInfo();
                            SGInfo.DISubgroupType = this.LocationTypeInfo;
                            SGInfo.Type           = this.LocationTypeInfo.Nid;
                            SGInfo.Name           = TotalTextValue + " " + LocationSubgroupName;

                            NewSubgroupNId = SGBuilder.CheckNCreateSubgroup(SGInfo);

                            //          Create relationship with new subgoup
                            SGValBuilder.InsertSubgroupValRelations(SubgroupValNId, NewSubgroupNId);
                        }
                        else
                        {
                            //      And If not
                            //          Check TOTAL is available under location or not
                            //              If not then create it under location
                            TotalNId = this.CheckNCreateTotalSubgroupUnderLocation(TotalTextValue);
                            //          Create relationship with Total
                            SGValBuilder.InsertSubgroupValRelations(SubgroupValNId, TotalNId);
                        }

                        IsSubgroupValInvalid = false;
                    }
                }
                else
                {
                    IsSubgroupValInvalid = false;
                }

                // Step 4.1: Get New subgroup val text
                NewSubgroupValText = DICommon.RemoveQuotes(SGValBuilder.CreateSubgroupValTextBySubgroupNids(string.Join(",", SGValBuilder.GetAssocaitedSubgroupsNId(SubgroupValNId).ToArray())));

                // Step 4.2: Update Subgroup Val text
                // SGValBuilder.UpdateSubgroupVals(SubgroupValNId, NewSubgroupValText, SGValInfo.Global, SGValInfo.GID);

                if (IsSubgroupValInvalid)
                {
                    // 4.2.1 create new subgorup under others dimension
                    SGInfo = new DI6SubgroupInfo();

                    // if subgorup val is equal to "total" only and no relationship found, then create total subgroup under location otherwise create it under others

                    if (string.IsNullOrEmpty(NewSubgroupValText) && (DI5SubgroupValText.Trim().ToLower() == TotalTextValue.Trim().ToLower() || DI5SubgroupValText.Trim().ToLower() == Constants.PrefixForNewValue.Trim().ToLower() + TotalTextValue.Trim().ToLower()))
                    {
                        SGInfo.DISubgroupType = this.LocationTypeInfo;
                        SGInfo.Type           = this.LocationTypeInfo.Nid;
                    }
                    else
                    {
                        SGInfo.DISubgroupType = this.OthersTypeInfo;
                        SGInfo.Type           = this.OthersTypeInfo.Nid;
                    }

                    SGInfo.Name = DI5SubgroupValText;

                    // check it is already exist or not. If not then only show it under log file
                    NewSubgroupNId = SGBuilder.GetSubgroupNid(string.Empty, DI5SubgroupValText);

                    if (NewSubgroupNId <= 0)
                    {
                        NewSubgroupNId = SGBuilder.CheckNCreateSubgroup(SGInfo);

                        if (SGInfo.Type != this.LocationTypeInfo.Nid)
                        {
                            // add subgorup into mismatch list
                            this.MismatchSubgroups.Add(DI5SubgroupValText);
                        }
                    }


                    // 4.2.2 delete relationship of subgroup val nid from subgroup_val_subgroup table
                    SGValBuilder.DeleteSubgroupValRelations(SubgroupValNId);

                    // 4.2.3 create subgroupval relationship with new subgroup
                    SGValBuilder.InsertSubgroupValRelations(SubgroupValNId, NewSubgroupNId);
                }
                else
                {
                    if (IsTotalSGFound)
                    {
                        if (IsLocationSubgroupExistsInSubgroup)
                        {
                            this.SubgroupsAddedWNewSubgorup.Add(NewSubgroupValText, SGInfo.Name);
                        }
                        else
                        {
                            this.SubgroupsAddedWithTotal.Add(NewSubgroupValText);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.ToString());
            }
        }