Example #1
0
        public static void GetParametersValue(CCSCascadedLookupField field, out string WebUrl, out string LookupListName, out string FieldParentLinkedFieldName, out string FieldLookupFieldName, out string FieldViewWhereString, out string FieldViewOrderString)
        {
            using (new EnterExitLogger("Utilities:GetParametersValue function"))
            {
                WebUrl                     = "";
                LookupListName             = "";
                FieldParentLinkedFieldName = "";
                FieldLookupFieldName       = "";
                FieldViewWhereString       = "";
                FieldViewOrderString       = "";

                string webUrl                = "";
                string lookupListName        = "";
                string LookupFieldName       = "";
                string ParentLinkedFieldName = "";
                string ViewWhereString       = "";
                string ViewOrderString       = "";
                Utils.LogManager.write("Field : " + field.Title);
                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    using (SPWeb LookupWeb = SPContext.Current.Site.OpenWeb(((SPFieldLookup)field).LookupWebId))
                    {
                        SPList LookupList = LookupWeb.Lists[new Guid(field.LookupFieldListName)];
                        webUrl            = LookupWeb.Url;
                        Utils.LogManager.write("webUrl : " + webUrl);

                        lookupListName = LookupList.Title;
                        Utils.LogManager.write("lookupListName : " + lookupListName);

                        LookupFieldName = field.LookupFieldName;
                        Utils.LogManager.write("LookupFieldName : " + LookupFieldName);


                        if (!string.IsNullOrEmpty(field.GetParentLinkedColumnId()))
                        {
                            //string linked_column = field.GetProperty(CustomDropDownList.LINK_COLUMN);
                            SPField ParentLinkedField = LookupList.Fields[new Guid(field.GetParentLinkedColumnId())];
                            if (ParentLinkedField != null)
                            {
                                ParentLinkedFieldName = ParentLinkedField.InternalName;
                                Utils.LogManager.write("ParentLinkedFieldName : " + ParentLinkedFieldName);
                            }
                        }

                        if (!string.IsNullOrEmpty(field.View))
                        {
                            SPView view = LookupList.GetView(new Guid(field.View));

                            if (!String.IsNullOrEmpty(view.Query))
                            {
                                string viewQueryXML         = string.Format("<Query>{0}</Query>", view.Query);
                                XmlDocument viewQueryXMLDoc = new XmlDocument();
                                viewQueryXMLDoc.LoadXml(viewQueryXML);
                                XmlNode whereNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("Where");
                                if (whereNode != null && !string.IsNullOrEmpty(whereNode.InnerXml))
                                {
                                    ViewWhereString = whereNode.InnerXml;
                                    Utils.LogManager.write("ViewWhereString : " + ViewWhereString);
                                }

                                XmlNode orderByNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("OrderBy");
                                if (orderByNode != null && !string.IsNullOrEmpty(orderByNode.InnerXml))
                                {
                                    ViewOrderString = orderByNode.InnerXml;
                                }

                                ViewOrderString = string.Format("<OrderBy>{0}</OrderBy>", ViewOrderString);
                                Utils.LogManager.write("ViewOrderString : " + ViewOrderString);
                            }
                        }
                    }
                });

                WebUrl                     = webUrl;
                LookupListName             = lookupListName;
                FieldParentLinkedFieldName = ParentLinkedFieldName;
                FieldLookupFieldName       = LookupFieldName;
                FieldViewWhereString       = ViewWhereString;
                FieldViewOrderString       = ViewOrderString;
            }
        }
Example #2
0
        public static void GetParametersValue(CCSCascadedLookupField field, out string WebUrl, out string LookupListName, out string FieldParentLinkedFieldName, out string FieldLookupFieldName, out string FieldViewWhereString, out string FieldViewOrderString)
        {
            using (new EnterExitLogger("Utilities:GetParametersValue function"))
            {
                WebUrl = ""; 
                LookupListName= "";
                FieldParentLinkedFieldName= "";
                FieldLookupFieldName= "";
                FieldViewWhereString= "";
                FieldViewOrderString = "";

                string webUrl = "";
                string lookupListName = "";
                string LookupFieldName = "";
                string ParentLinkedFieldName = "";
                string ViewWhereString = "";
                string ViewOrderString = "";
                Utils.LogManager.write("Field : " + field.Title);
                SPSecurity.RunWithElevatedPrivileges(delegate
                    {
                        using (SPWeb LookupWeb = SPContext.Current.Site.OpenWeb(((SPFieldLookup)field).LookupWebId))
                        {
                            SPList LookupList = LookupWeb.Lists[new Guid(field.LookupFieldListName)];
                            webUrl = LookupWeb.Url;
                            Utils.LogManager.write("webUrl : " + webUrl);

                            lookupListName = LookupList.Title;
                            Utils.LogManager.write("lookupListName : " + lookupListName);

                            LookupFieldName = field.LookupFieldName;
                            Utils.LogManager.write("LookupFieldName : " + LookupFieldName);


                            if (!string.IsNullOrEmpty(field.GetParentLinkedColumnId()))
                            {
                                //string linked_column = field.GetProperty(CustomDropDownList.LINK_COLUMN);
                                SPField ParentLinkedField = LookupList.Fields[new Guid(field.GetParentLinkedColumnId())];
                                if (ParentLinkedField != null)
                                {
                                    ParentLinkedFieldName = ParentLinkedField.InternalName;
                                    Utils.LogManager.write("ParentLinkedFieldName : " + ParentLinkedFieldName);
                                }
                            }

                            if (!string.IsNullOrEmpty(field.View))
                            {
                                SPView view = LookupList.GetView(new Guid(field.View));

                                if (!String.IsNullOrEmpty(view.Query))
                                {
                                    string viewQueryXML = string.Format("<Query>{0}</Query>", view.Query);
                                    XmlDocument viewQueryXMLDoc = new XmlDocument();
                                    viewQueryXMLDoc.LoadXml(viewQueryXML);
                                    XmlNode whereNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("Where");
                                    if (whereNode != null && !string.IsNullOrEmpty(whereNode.InnerXml))
                                    {
                                        ViewWhereString = whereNode.InnerXml;
                                        Utils.LogManager.write("ViewWhereString : " + ViewWhereString);
                                    }

                                    XmlNode orderByNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("OrderBy");
                                    if (orderByNode != null && !string.IsNullOrEmpty(orderByNode.InnerXml))
                                    {
                                        ViewOrderString = orderByNode.InnerXml;
                                    }

                                    ViewOrderString = string.Format("<OrderBy>{0}</OrderBy>", ViewOrderString);
                                    Utils.LogManager.write("ViewOrderString : " + ViewOrderString);
                                }
                            }
                        }
                    });

                WebUrl = webUrl;
                LookupListName = lookupListName;
                FieldParentLinkedFieldName = ParentLinkedFieldName;
                FieldLookupFieldName = LookupFieldName;
                FieldViewWhereString = ViewWhereString;
                FieldViewOrderString = ViewOrderString;
            }
        }
Example #3
0
        public static void FetchMatchedValuesFromList(CCSCascadedLookupField field, string parentFieldValue, ref List <ListItem> itemList)
        {
            using (new EnterExitLogger("Utilities:FetchMatchedValuesFromList function"))
            {
                SPListItemCollection matchedItemList = null;

                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    using (SPWeb LookupWeb = SPContext.Current.Site.OpenWeb(((SPFieldLookup)field).LookupWebId))
                    {
                        SPList LookupList = LookupWeb.Lists[new Guid(field.LookupFieldListName)];

                        SPField ParentLinkedField = LookupList.Fields[new Guid(field.GetParentLinkedColumnId())];

                        SPQuery query = new SPQuery();

                        string fetchItemConditionString = "<Eq><FieldRef Name='" + ParentLinkedField.InternalName + "' LookupId='TRUE'/><Value Type='Lookup'>" + parentFieldValue + "</Value></Eq>";

                        if (string.IsNullOrEmpty(field.View))
                        {
                            query.Query = "<Where>" + fetchItemConditionString + "</Where>";
                        }
                        else
                        {
                            string viewQueryWhereString   = "";
                            string viewQueryOrderByString = "";

                            SPView view = LookupList.GetView(new Guid(field.View));

                            if (!String.IsNullOrEmpty(view.Query))
                            {
                                string viewQueryXML         = string.Format("<Query>{0}</Query>", view.Query);
                                XmlDocument viewQueryXMLDoc = new XmlDocument();
                                viewQueryXMLDoc.LoadXml(viewQueryXML);
                                XmlNode whereNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("Where");
                                if (whereNode != null && !string.IsNullOrEmpty(whereNode.InnerXml))
                                {
                                    viewQueryWhereString = whereNode.InnerXml;
                                }

                                XmlNode orderByNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("OrderBy");
                                if (orderByNode != null && !string.IsNullOrEmpty(orderByNode.InnerXml))
                                {
                                    viewQueryOrderByString = orderByNode.InnerXml;
                                }

                                viewQueryOrderByString = string.Format("<OrderBy>{0}</OrderBy>", viewQueryOrderByString);
                            }

                            if (!String.IsNullOrEmpty(viewQueryWhereString))
                            {
                                query.Query = "<Where><And>" + viewQueryWhereString + fetchItemConditionString + "</And></Where>" + viewQueryOrderByString;
                            }
                            else
                            {
                                query.Query = "<Where>" + fetchItemConditionString + "</Where>";
                            }
                        }

                        Utils.LogManager.write("Item fetch Query: " + query.Query);

                        matchedItemList = LookupList.GetItems(query);
                        Utils.LogManager.write("matchedItemList item Count: " + matchedItemList.Count);
                    }
                });
                foreach (SPListItem item in matchedItemList)
                {
                    //ListItem newItem = new ListItem(Convert.ToString(item.Fields[new Guid(field.LookupFieldName)].GetFieldValueAsText(item[new Guid(field.LookupFieldName)])), item.ID.ToString());
                    ListItem newItem = new ListItem(Convert.ToString(item.Fields.GetFieldByInternalName(field.LookupFieldName).GetFieldValueAsText(item[item.Fields.GetFieldByInternalName(field.LookupFieldName).Id])), item.ID.ToString());
                    if (!itemList.Contains(newItem))
                    {
                        itemList.Add(newItem);
                    }
                }
                Utils.LogManager.write("itemList item Count: " + itemList.Count);
            }
        }
Example #4
0
        public static void FetchMatchedValuesFromList(CCSCascadedLookupField field, string parentFieldValue, ref List<ListItem> itemList)
        {
            using (new EnterExitLogger("Utilities:FetchMatchedValuesFromList function"))
            {
                SPListItemCollection matchedItemList = null;

                SPSecurity.RunWithElevatedPrivileges(delegate
                    {
                        using (SPWeb LookupWeb = SPContext.Current.Site.OpenWeb(((SPFieldLookup)field).LookupWebId))
                        {
                            SPList LookupList = LookupWeb.Lists[new Guid(field.LookupFieldListName)];

                            SPField ParentLinkedField = LookupList.Fields[new Guid(field.GetParentLinkedColumnId())];

                            SPQuery query = new SPQuery();

                            string fetchItemConditionString = "<Eq><FieldRef Name='" + ParentLinkedField.InternalName + "' LookupId='TRUE'/><Value Type='Lookup'>" + parentFieldValue + "</Value></Eq>";

                            if (string.IsNullOrEmpty(field.View))
                            {
                                query.Query = "<Where>" + fetchItemConditionString + "</Where>";
                            }
                            else
                            {
                                string viewQueryWhereString = "";
                                string viewQueryOrderByString = "";

                                SPView view = LookupList.GetView(new Guid(field.View));

                                if (!String.IsNullOrEmpty(view.Query))
                                {
                                    string viewQueryXML = string.Format("<Query>{0}</Query>", view.Query);
                                    XmlDocument viewQueryXMLDoc = new XmlDocument();
                                    viewQueryXMLDoc.LoadXml(viewQueryXML);
                                    XmlNode whereNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("Where");
                                    if (whereNode != null && !string.IsNullOrEmpty(whereNode.InnerXml))
                                    {
                                        viewQueryWhereString = whereNode.InnerXml;
                                    }

                                    XmlNode orderByNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("OrderBy");
                                    if (orderByNode != null && !string.IsNullOrEmpty(orderByNode.InnerXml))
                                    {
                                        viewQueryOrderByString = orderByNode.InnerXml;
                                    }

                                    viewQueryOrderByString = string.Format("<OrderBy>{0}</OrderBy>", viewQueryOrderByString);
                                }

                                if (!String.IsNullOrEmpty(viewQueryWhereString))
                                {
                                    query.Query = "<Where><And>" + viewQueryWhereString + fetchItemConditionString + "</And></Where>" + viewQueryOrderByString;
                                }
                                else
                                {
                                    query.Query = "<Where>" + fetchItemConditionString + "</Where>";
                                }
                            }

                            Utils.LogManager.write("Item fetch Query: " + query.Query);

                            matchedItemList = LookupList.GetItems(query);
                            Utils.LogManager.write("matchedItemList item Count: " + matchedItemList.Count);
                        }
                    });
                foreach (SPListItem item in matchedItemList)
                {
                    //ListItem newItem = new ListItem(Convert.ToString(item.Fields[new Guid(field.LookupFieldName)].GetFieldValueAsText(item[new Guid(field.LookupFieldName)])), item.ID.ToString());
                    ListItem newItem = new ListItem(Convert.ToString(item.Fields.GetFieldByInternalName(field.LookupFieldName).GetFieldValueAsText(item[item.Fields.GetFieldByInternalName(field.LookupFieldName).Id])), item.ID.ToString());
                    if (!itemList.Contains(newItem))
                    {
                        itemList.Add(newItem);
                    }
                }
                Utils.LogManager.write("itemList item Count: " + itemList.Count);
            }
        }