Exemplo n.º 1
0
        public List <NBrightInfo> GetListByUserDataInfoVar(string typeCode, string webserviceurl = "")
        {
            try
            {
                var weblist     = new List <NBrightInfo>();
                var recordCount = 0;

                // in some ascx we want to run a wesvice on the OnLoad event, the base.OnLoad doesn;t allow us to pass the webservice url, so we can use this to override the normal function and force a webservice to be used.
                if (!string.IsNullOrEmpty(OverRideWebserviceUrl))
                {
                    webserviceurl = OverRideWebserviceUrl;
                }

                if (EntityTypeCode == "" && !string.IsNullOrEmpty(webserviceurl))
                {
                    // No EntityType, therefore data must be selected from WebService.
                    var l      = new List <NBrightInfo>();
                    var xmlDoc = new XmlDocument();

                    // pass the userdatainfo into the header request (saves using or creating a post field or adding to url)
                    var objInfo      = ObjCtrl.Get(UInfo.ItemId);
                    var userdatainfo = "";
                    if (objInfo != null)
                    {
                        if (objInfo.TypeCode == "USERDATAINFO")
                        {
                            //userdatainfo = DotNetNuke.Common.Globals.HTTPPOSTEncode(objInfo.XMLData);
                            userdatainfo = objInfo.XMLData;
                        }
                    }

                    string strResp = DnnUtils.GetDataResponseAsString(webserviceurl, "userdatainfo", userdatainfo);
                    try
                    {
                        xmlDoc.LoadXml(strResp);
                    }
                    catch (Exception)
                    {
                        return(null);
                    }

                    var rc = xmlDoc.SelectSingleNode("root/recordcount");
                    if (rc != null && Utils.IsNumeric(rc.InnerText))
                    {
                        recordCount = Convert.ToInt32(rc.InnerText);
                    }

                    var xmlNodeList = xmlDoc.SelectNodes("root/item");
                    if (xmlNodeList != null)
                    {
                        foreach (XmlNode xmlNod in xmlNodeList)
                        {
                            var obj = new NBrightInfo();
                            obj.FromXmlItem(xmlNod.OuterXml);
                            l.Add(obj);
                        }
                    }
                    weblist = l;
                    if (recordCount == 0)
                    {
                        recordCount = weblist.Count;
                    }
                }
                else
                {
                    if (OverRideInfoList != null)
                    {
                        recordCount = OverRideInfoList.Count;
                    }
                    else
                    {
                        recordCount = ObjCtrl.GetListCount(UInfo.SearchPortalId, UInfo.SearchModuleId, EntityTypeCode, UInfo.SearchFilters, EntityTypeCodeLang, EntityLangauge);
                    }
                }


                if (!Utils.IsNumeric(UInfo.SearchPageNumber))
                {
                    UInfo.SearchPageNumber = "1";
                }
                UInfo.SearchPageSize = GenXmlFunctions.GetHiddenField(CtrlSearch, "searchpagesize");
                if (UInfo.SearchPageSize == "")
                {
                    UInfo.SearchPageSize = GenXmlFunctions.GetHiddenField(CtrlSearch, "pagesize");
                }
                UInfo.SearchReturnLimit = GenXmlFunctions.GetHiddenField(CtrlSearch, "searchreturnlimit");
                if (!Utils.IsNumeric(UInfo.SearchPageSize))
                {
                    UInfo.SearchPageSize = "25";
                }
                if (!Utils.IsNumeric(UInfo.SearchReturnLimit))
                {
                    UInfo.SearchReturnLimit = "0";
                }

                if (_activatePaging)
                {
                    CtrlPaging.PageSize     = Convert.ToInt32(UInfo.SearchPageSize);
                    CtrlPaging.TotalRecords = recordCount;
                    CtrlPaging.CurrentPage  = Convert.ToInt32(UInfo.SearchPageNumber);
                    CtrlPaging.BindPageLinks();
                }
                else
                {
                    CtrlPaging.Visible = false;
                }

                if (UInfo.SearchClearAfter == "1")
                {
                    UInfo.ClearSearchData();
                }

                if (OverRideInfoList != null)
                {
                    //overiding list passed from control, so use linq to do the paging, select
                    var records = (from o in OverRideInfoList select o);

                    var pgNo  = Convert.ToInt32(UInfo.SearchPageNumber);
                    var pgRec = Convert.ToInt32(UInfo.SearchPageSize);

                    var rtnRecords = records.Skip((pgNo - 1) * pgRec).Take(pgRec).ToList();

                    return(rtnRecords);
                }

                if (EntityTypeCode == "" & webserviceurl != "")
                {
                    // use website (Might be empty).
                    return(weblist);
                }
                else
                {
                    var l = GetList(UInfo.SearchPortalId, UInfo.SearchModuleId, EntityTypeCode, UInfo.SearchFilters, UInfo.SearchOrderby, Convert.ToInt32(UInfo.SearchReturnLimit), Convert.ToInt32(UInfo.SearchPageNumber), Convert.ToInt32(UInfo.SearchPageSize), recordCount, EntityTypeCodeLang, EntityLangauge);
                    return(l);
                }
            }
            catch (Exception)
            {
                //clear data incase error in userdata
                UInfo.ClearSearchData();
                throw;
            }
        }