Ejemplo n.º 1
0
        public override void ItemUpdated(SPItemEventProperties properties)
        {
            var ct       = properties.ListItem.ContentType;
            var setting  = ct.GetCustomSettings <AutoCreationSettings>(AIAPortalFeatures.Infrastructure);
            var listItem = properties.ListItem;

            if (setting == null || !setting.RunOnCreated || !setting.EnableCreateList)
            {
                return;
            }
            if (setting.EnableCreateList)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    var url = listItem[setting.UrlFieldName].ToString();
                    var arr = url.Split(new char[] { ',' });
                    SPFieldUrlValue fieldValue = new SPFieldUrlValue(url);
                    fieldValue.Description     = listItem.Title;
                    //fieldValue.Url = arr[1];

                    using (DisableItemEvent disableItemEvent = new DisableItemEvent())
                    {
                        listItem[setting.UrlFieldName] = fieldValue;
                        listItem.SystemUpdate();
                    }
                });
            }
        }
Ejemplo n.º 2
0
        private void CreateList(SPListItem listItem, SPWeb web, ListIntanceDefinition definition, string UrlFieldName, out string listUrl)
        {
            listUrl = string.Empty;
            try
            {
                var template = web.ListTemplates.Cast <SPListTemplate>().Where(p => p.Name == definition.TemplateName).FirstOrDefault();
                if (template == null)
                {
                    return;
                }
                string title = listItem.GetFormulaValue(definition.Title);
                string url   = listItem.GetFormulaValue(definition.Url).Simplyfied();
                if (template.CategoryType == SPListCategoryType.CustomLists)
                {
                    url = "Lists/" + url;
                }

                var listId = web.Lists.Add(title, string.Empty, url, template.FeatureId.ToString(), template.Type_Client, "100", SPListTemplate.QuickLaunchOptions.Default);
                // Guid listId = web.Lists.Add(item.Title, item.Description, item.Url, template.FeatureId.ToString(), item.TemplateId, "100");

                SPList list = web.Lists[listId];
                list.ContentTypesEnabled = true;
                list.EnableVersioning    = true;
                list.EnableModeration    = true; //enable Content Approval
                foreach (var item in definition.ContentTypes)
                {
                    list.EnsureContentTypeInList(item);
                }

                var urlValue = new SPFieldUrlValue();
                urlValue.Description = title;
                urlValue.Url         = web.Url + "/" + url;

                using (DisableItemEvent disableItemEvent = new DisableItemEvent())
                {
                    listItem[UrlFieldName] = urlValue;
                    listItem.Update();
                }


                listUrl = urlValue.Url;
                list.Update();
            }
            catch (Exception ex)
            {
                Utility.LogError(ex.Message + ex.StackTrace, AIAPortalFeatures.Infrastructure);
                //throw;
            }
        }
Ejemplo n.º 3
0
        private void IncreaseItemOrderNo(SPItemEventProperties properties)
        {
            if (properties.AfterProperties[Constants.ORDER_NUMBER_COLUMN] != null && !string.IsNullOrEmpty(properties.AfterProperties[Constants.ORDER_NUMBER_COLUMN].ToString()))
            {
                int orderNo = 0;
                int.TryParse(properties.AfterProperties[Constants.ORDER_NUMBER_COLUMN].ToString(), out orderNo);

                if (orderNo != 0)
                {
                    string strItemId = properties.ListItem == null ? "0" : properties.ListItemId.ToString();

                    string caml           = string.Empty;
                    var    expressionsAnd = new List <Expression <Func <SPListItem, bool> > >();

                    expressionsAnd.Add(x => ((int)x[Constants.ORDER_NUMBER_COLUMN]) >= orderNo);
                    expressionsAnd.Add(x => (x["ID"]) != (DataTypes.Counter)strItemId);

                    //if (properties.AfterProperties[Constants.MENU_KEYWORDS_COLUMN] != null)
                    //{
                    //    expressionsAnd.Add(x => ((string)x[Constants.MENU_KEYWORDS_COLUMN]) == properties.AfterProperties[Constants.MENU_KEYWORDS_COLUMN].ToString());
                    //}

                    caml = Camlex.Query().WhereAll(expressionsAnd).OrderBy(x => x[Constants.ORDER_NUMBER_COLUMN] as Camlex.Asc).ToString();

                    SPQuery spQuery = new SPQuery();
                    spQuery.Query = caml;

                    SPList currentList         = properties.List;
                    SPListItemCollection items = currentList.GetItems(spQuery);

                    foreach (SPListItem item in items)
                    {
                        orderNo++;

                        using (DisableItemEvent scope = new DisableItemEvent())
                        {
                            item[Constants.ORDER_NUMBER_COLUMN] = orderNo;
                            item.SystemUpdate(false);
                        }
                    }
                }
            }
            else
            {
                properties.AfterProperties[Constants.ORDER_NUMBER_COLUMN] = GetLatestItemOrderNo(properties) + 1;
            }
        }
Ejemplo n.º 4
0
 public static void SetCustomProperty(this SPListItem listItem, string key, string value)
 {
     using (DisableItemEvent disableItemEvent = new DisableItemEvent())
     {
         try
         {
             listItem.Properties[key] = value;
             listItem.SystemUpdate();
         }
         catch
         {
             using (SPWeb web = listItem.ParentList.ParentWeb)
             {
                 web.AllowUnsafeUpdates = true;
                 SPList     list = web.Lists[listItem.ParentList.ID];
                 SPListItem item = list.GetItemById(listItem.ID);
                 item.Properties[key] = value;
                 item.SystemUpdate();
                 web.AllowUnsafeUpdates = false;
             }
         }
     }
 }
Ejemplo n.º 5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            int orderNo = 0;

            int.TryParse(txtOrderNo.Text, out orderNo);

            if (orderNo != 0)
            {
                string listId    = Request.QueryString["ListId"];
                string itemId    = Request.QueryString["ID"];
                string sourceUrl = Request.QueryString["Source"];

                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                    {
                        using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
                        {
                            web.AllowUnsafeUpdates = true;

                            try
                            {
                                SPList curList     = web.Lists[new Guid(listId)];
                                SPListItem curItem = curList.Items.GetItemById(Convert.ToInt32(itemId));

                                string caml        = string.Empty;
                                var expressionsAnd = new List <Expression <Func <SPListItem, bool> > >();

                                expressionsAnd.Add(x => ((int)x[Constants.ORDER_NUMBER_COLUMN]) >= orderNo);
                                expressionsAnd.Add(x => (x["ID"]) != (DataTypes.Counter)itemId);

                                caml = Camlex.Query().WhereAll(expressionsAnd).OrderBy(x => x[Constants.ORDER_NUMBER_COLUMN] as Camlex.Asc).ToString();

                                SPQuery spQuery = new SPQuery();
                                spQuery.Query   = caml;

                                SPListItemCollection items = curList.GetItems(spQuery);

                                using (DisableItemEvent scope = new DisableItemEvent())
                                {
                                    curItem[Constants.ORDER_NUMBER_COLUMN] = orderNo;
                                    curItem.SystemUpdate(false);
                                }

                                foreach (SPListItem item in items)
                                {
                                    orderNo++;

                                    using (DisableItemEvent scope = new DisableItemEvent())
                                    {
                                        item[Constants.ORDER_NUMBER_COLUMN] = orderNo;
                                        item.SystemUpdate(false);
                                    }
                                }
                            }
                            catch (Exception ex) { }
                            finally
                            {
                                web.AllowUnsafeUpdates = false;
                            }
                        }
                    }
                });
            }

            ClosePopup();
        }