コード例 #1
0
        private List <KeyValue> LoadList()
        {
            if (!externalDataSourceType)
            {
                //return new List<KeyValue>();
            }

            if (DataSourceType == "KeyValue")
            {
                list = this.ownerPage.GetAllKeyValueByKeyTypeIntCode(KeyTypeIntCode).OrderBy(e => e.Name).ToList();
                if (this.AddingDefaultValue)
                {
                    AddDefaultValue(list, this.UseShortDefaultValue);
                }
                if (OrderBy != null)
                {
                    list = BaseClassBL <KeyValue> .Sort(list, this.OrderBy, this.OrderDirection != null?this.OrderDirection : "asc").ToList();
                }
            }
            else if (DataSourceType == "Role")
            {
                list = (from e in this.AdminClientRef.GetAllRoles("Name", this.GridViewSortDirection)
                        select new KeyValue
                {
                    idKeyValue = e.idRole,
                    Name = e.Name
                }).ToList <KeyValue>();

                AddDefaultValue(list);
            }
            //else if (DataSourceType == "UNI")
            //{
            //    CallContext resultContext = new CallContext();

            //    resultContext.CurrentYear = this.CurrentYear;
            //    resultContext.CurrentPeriod = this.CurrentPeriod;

            //    UNI currentUni = this.AdminClientRef.GetCurrentUNI(resultContext);
            //    KeyValue kvUni = new KeyValue
            //    {
            //        idKeyType = currentUni.idUNI,
            //        Name=currentUni.UniName
            //    };

            //     list = new List<KeyValue>();
            //     list.Add(kvUni);

            //     AddDefaultValue(list);
            //}
            else if (DataSourceType == "VendorDiePriceList")
            {
                DateTime?dateActiveTo = null;
                if (!string.IsNullOrWhiteSpace(this.AdditionalParam))
                {
                    dateActiveTo = Convert.ToDateTime(this.AdditionalParam, BaseHelper.GetDateTimeFormatInfo());
                }

                var data = this.CostCalculationRef.GetAllDiePriceList(new List <AbstractSearch>(), dateActiveTo, string.Empty, string.Empty);

                list = (from d in data
                        select new KeyValue
                {
                    idKeyValue = d.idDiePriceList,
                    Name = d.VendorName + " / from " + d.DateFromString + (d.DateTo.HasValue ? " - to " + d.DateToString : string.Empty)
                }).ToList();

                AddDefaultValue(list);
            }

            else if (DataSourceType == "Country")
            {
                var data = this.AdminClientRef.GetAllCountries();

                //премахваме от списъка с държави текста "без гражданство" AdditionalParam="Number <> 0"
                if (!string.IsNullOrEmpty(this.AdditionalParam) && this.AdditionalParam == "WithoutEmptyCountry")
                {
                    list = (from c in data
                            where c.CodeISO3166 == ETEMEnums.CountryCodeEnum.BG.ToString()
                            select new KeyValue
                    {
                        idKeyValue = c.idCountry,
                        Name = c.Name
                    }
                            ).Union(from c in data
                                    where c.CodeISO3166 != ETEMEnums.CountryCodeEnum.NONE.ToString() && c.CodeISO3166 != ETEMEnums.CountryCodeEnum.BG.ToString()
                                    select new KeyValue
                    {
                        idKeyValue = c.idCountry,
                        Name       = c.Name
                    }
                                    ).ToList <KeyValue>();
                }

                else
                {
                    list = (from c in data
                            where c.CodeISO3166 == ETEMEnums.CountryCodeEnum.NONE.ToString()
                            select new KeyValue
                    {
                        idKeyValue = c.idCountry,
                        Name = c.Name
                    }).Union(from c in data
                             where c.CodeISO3166 == ETEMEnums.CountryCodeEnum.BG.ToString()
                             select new KeyValue
                    {
                        idKeyValue = c.idCountry,
                        Name       = c.Name
                    }
                             ).Union(from c in data
                                     where c.CodeISO3166 != ETEMEnums.CountryCodeEnum.NONE.ToString() && c.CodeISO3166 != ETEMEnums.CountryCodeEnum.BG.ToString()
                                     select new KeyValue
                    {
                        idKeyValue = c.idCountry,
                        Name       = c.Name
                    }
                                     ).ToList <KeyValue>();
                }

                AddDefaultValue(list);
            }
            else if (DataSourceType == "District")
            {
                if (string.IsNullOrEmpty(this.AdditionalParam))
                {
                    list = (from d in this.AdminClientRef.GetAllDistricts()
                            select new KeyValue
                    {
                        idKeyValue = d.idDistrict,
                        Name = d.Name
                    }).ToList <KeyValue>();
                }
                else
                {
                    list = (from d in this.AdminClientRef.GetDistrictsByCountryId(this.AdditionalParam)
                            select new KeyValue
                    {
                        idKeyValue = d.idDistrict,
                        Name = d.Name
                    }).ToList <KeyValue>();
                }

                AddDefaultValue(list);
            }
            else if (DataSourceType == "Municipality")
            {
                if (string.IsNullOrEmpty(this.AdditionalParam))
                {
                    list = (from m in this.AdminClientRef.GetAllMunicipalities()
                            select new KeyValue
                    {
                        idKeyValue = m.idMunicipality,
                        Name = m.Name
                    }).ToList <KeyValue>();
                }
                else
                {
                    string idFilter = Constants.INVALID_ID_STRING;
                    if (this.AdditionalParam.Contains("Country"))
                    {
                        if (this.AdditionalParam.Contains("="))
                        {
                            idFilter = this.AdditionalParam.Split('=')[1];
                        }
                        else
                        {
                            idFilter = this.AdditionalParam;
                        }

                        list = (from m in this.AdminClientRef.GetMunicipalitiesByCountryId(idFilter)
                                select new KeyValue
                        {
                            idKeyValue = m.idMunicipality,
                            Name = m.Name
                        }).ToList <KeyValue>();
                    }
                    else if (this.AdditionalParam.Contains("District"))
                    {
                        if (this.AdditionalParam.Contains("="))
                        {
                            idFilter = this.AdditionalParam.Split('=')[1];
                        }
                        else
                        {
                            idFilter = this.AdditionalParam;
                        }

                        list = (from m in this.AdminClientRef.GetMunicipalitiesByDistrictId(idFilter)
                                select new KeyValue
                        {
                            idKeyValue = m.idMunicipality,
                            Name = m.Name
                        }).ToList <KeyValue>();
                    }
                    else
                    {
                        list = new List <KeyValue>();
                    }
                }

                AddDefaultValue(list);
            }
            else if (DataSourceType == "EKATTE")
            {
                if (string.IsNullOrEmpty(this.AdditionalParam))
                {
                    list = (from e in this.AdminClientRef.GetAllEKATTEs()
                            select new KeyValue
                    {
                        idKeyValue = e.idEKATTE,
                        Name = e.Name
                    }).ToList <KeyValue>();
                }
                else
                {
                    list = (from e in this.AdminClientRef.GetEKATTEsByMunicipalityId(this.AdditionalParam)
                            select new KeyValue
                    {
                        idKeyValue = e.idEKATTE,
                        Name = e.Name
                    }).ToList <KeyValue>();
                }

                AddDefaultValue(list);
            }

            else if (DataSourceType == "Location")
            {
                if (string.IsNullOrEmpty(this.AdditionalParam))
                {
                    list = (from l in this.AdminClientRef.GetAllLocations()
                            select new KeyValue
                    {
                        idKeyValue = l.idLocation,
                        Name = l.Name
                    }).ToList <KeyValue>();
                }
                else
                {
                    list = (from l in this.AdminClientRef.GetLocationsByMunicipalityId(this.AdditionalParam)
                            select new KeyValue
                    {
                        idKeyValue = l.idLocation,
                        Name = l.Name
                    }).ToList <KeyValue>();
                }

                AddDefaultValue(list);
            }
            else if (DataSourceType == "LocationView")
            {
                if (string.IsNullOrEmpty(this.AdditionalParam))
                {
                    list = (from lv in this.AdminClientRef.GetAllLocationViews()
                            select new KeyValue
                    {
                        idKeyValue = lv.idLocation,
                        Name = lv.LocationTypeName
                    }).ToList <KeyValue>();
                }
                else
                {
                    list = (from lv in this.AdminClientRef.GetLocationViewsByMunicipalityId(this.AdditionalParam)
                            select new KeyValue
                    {
                        idKeyValue = lv.idLocation,
                        Name = lv.LocationTypeName
                    }).ToList <KeyValue>();
                }

                AddDefaultValue(list);
            }



            else if (DataSourceType == "WeekOfMonth")
            {
                list = new List <KeyValue>();

                int reportYear  = Int32.Parse(CustomFieldUseEverything.Split('|')[0]);
                int reportMonth = Int32.Parse(CustomFieldUseEverything.Split('|')[1]);

                int weeksCount = BaseHelper.Weeks(reportYear, reportMonth);

                for (int i = 0; i < weeksCount; i++)
                {
                    int week = i + 1;

                    if (string.IsNullOrEmpty(this.WeekNotEQ) || !this.WeekNotEQ.Contains(i.ToString()))
                    {
                        list.Add(new KeyValue()
                        {
                            Name       = "Седмица " + week,
                            idKeyValue = i
                        }
                                 );
                    }
                }
            }
            else if (DataSourceType == "Group")
            {
                ICollection <AbstractSearch> searchCriteria = new List <AbstractSearch>();
                if (!string.IsNullOrEmpty(AdditionalParam))
                {
                    searchCriteria.Add(
                        new BooleanSearch
                    {
                        Comparator = BooleanComparators.Equal,
                        Property   = "SharedAccess",
                        SearchTerm = Convert.ToBoolean("true")
                    });
                }


                list = (from d in this.AdminClientRef.GetGroupDataView(searchCriteria, "", "")
                        select new KeyValue
                {
                    idKeyValue = d.idGroup,
                    Name = d.GroupName
                }).DistinctBy(o => o.idKeyValue).ToList <KeyValue>();

                AddDefaultValue(list);
            }

            else if (DataSourceType == "Modules")
            {
                list = (from e in this.AdminClientRef.GetAllModule(new List <AbstractSearch>(), "ModuleName", this.GridViewSortDirection)
                        select new KeyValue
                {
                    idKeyValue = e.idModule,
                    Name = e.ModuleName
                }).ToList <KeyValue>();

                AddDefaultValue(list);
            }
            else if (DataSourceType == "PRESS")
            {
                list = this.ownerPage.GetAllKeyValueByKeyTypeIntCode(KeyTypeIntCode).Where(s => s.DefaultValue1 == "Press").OrderBy(e => e.Name).ToList();

                if (this.AddingDefaultValue)
                {
                    AddDefaultValue(list, this.UseShortDefaultValue);
                }
                if (OrderBy != null)
                {
                    list = BaseClassBL <KeyValue> .Sort(list, this.OrderBy, this.OrderDirection != null?this.OrderDirection : "asc").ToList();
                }
            }
            else if (DataSourceType == "ProfileSetting")
            {
                var data = this.ownerPage.CostCalculationRef.GetProfilesList(new List <AbstractSearch>(), "", "");

                list = (from ps in data
                        select new KeyValue
                {
                    idKeyValue = ps.idProfileSetting,
                    Name = ps.ProfileName
                }).ToList <KeyValue>();

                AddDefaultValue(list);
            }
            else
            {
                list = new List <KeyValue>();
            }

            return(list);
        }