Exemple #1
0
        private static void AddUserControlToPage(SPWeb web, string pageName, string pageTitle, string positionName, int positionNumber, string userControlName)
        {
            var webUrl = web.ServerRelativeUrl;

            if (webUrl.Equals("/"))
            {
                webUrl = "";
            }
            ContainerWebPart containerWebPart = WebPartHelper.GetContainerWebPart(web);

            if (containerWebPart != null)
            {
                containerWebPart.Title = pageTitle;
                //containerWebPart.UserControlPath = "UserControls/" + userControlName + ".ascx";
                containerWebPart.UserControlPath = webUrl + "/" + ListsName.InternalName.ResourcesList + "/" + userControlName + ".ascx";
                WebPartHelper.AddWebPart(web, pageName + ".aspx", containerWebPart, positionName, positionNumber);
            }
        }
Exemple #2
0
 /// <summary>
 /// Load default value to control and other initialize.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Page_Load(object sender, EventArgs e)
 {
     divDV.Visible   = false;
     divSDTC.Visible = false;
     parentWebpart   = this.Parent as ContainerWebPart;
     if ("SoDoToChucUC".Equals(parentWebpart.Title))
     {
         divSDTC.Visible          = true;
         rptToChuc.ItemDataBound += new RepeaterItemEventHandler(rptToChuc_ItemDataBound);
         currentCatId             = HttpContext.Current.Request.QueryString["CatId"];
         if (!Page.IsPostBack)
         {
             Utilities.BindOrganizationToRpt(CurrentWeb, rptToChuc, ListsName.InternalName.CategoryList, FieldsName.CategoryList.InternalName.CategoryLevel,
                                             "Text", "2", FieldsName.CategoryList.InternalName.Order);
         }
     }
     else if ("SoDoToChucDefaultPageUC".Equals(parentWebpart.Title))
     {
         divDV.Visible            = true;
         rptToChuc.ItemDataBound += new RepeaterItemEventHandler(rptToChuc_ItemDataBound);
         //Bind source to menu with type is Đơn vị
         MenuBO.BindMenu(CurrentWeb, ListsName.InternalName.MenuList, rptToChuc, "Đơn vị");
     }
 }
 /// <summary>
 /// Load default value to control and other initialize.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Page_Load(object sender, EventArgs e)
 {
     divDV.Visible = false;
     divSDTC.Visible = false;
     parentWebpart = this.Parent as ContainerWebPart;
     if ("SoDoToChucUC".Equals(parentWebpart.Title))
     {
         divSDTC.Visible = true;
         rptToChuc.ItemDataBound += new RepeaterItemEventHandler(rptToChuc_ItemDataBound);
         currentCatId = HttpContext.Current.Request.QueryString["CatId"];
         if (!Page.IsPostBack)
         {
             Utilities.BindOrganizationToRpt(CurrentWeb, rptToChuc, ListsName.InternalName.CategoryList, FieldsName.CategoryList.InternalName.CategoryLevel,
                 "Text", "2", FieldsName.CategoryList.InternalName.Order);
         }
     }
     else if ("SoDoToChucDefaultPageUC".Equals(parentWebpart.Title))
     {
         divDV.Visible = true;
         rptToChuc.ItemDataBound += new RepeaterItemEventHandler(rptToChuc_ItemDataBound);
         //Bind source to menu with type is Đơn vị
         MenuBO.BindMenu(CurrentWeb, ListsName.InternalName.MenuList, rptToChuc, "Đơn vị");
     }
 }
        public override IResult Parse(object source)
        {
            if (null == source)
            {
                throw new ArgumentNullException("source");
            }
            ContainerWebPart webPart = source as ContainerWebPart;

            if (null == webPart)
            {
                throw new ArgumentException("source is not an ContainerWebPart");
            }
            IConfiguration config = webPart.Configuration;

            if (null == config)
            {
                throw new ArgumentException("missing configuration");
            }
            IValidationManager validationManager = webPart.ValidationManager;

            if (null == validationManager)
            {
                throw new ArgumentException("missing validation manager");
            }
            base.Parse(source);
            if (config.Sections.ContainsKey("Template"))
            {
                IConfigurationSection templateConfig = config.GetConfigurationSectionReference("Template");
                webPart.TemplateConfig = templateConfig;
            }
            else
            {
                webPart.TemplateConfig = config.NewConfigurationSectionInstance("Template");
            }
            if (config.Sections.ContainsKey("Validation"))
            {
                foreach (IConfigurationElement element in config.Sections["Validation"].Elements.Values)
                {
                    IValidationTask task = validationManager.NewValidationTaskInstance();
                    if (element.Attributes.ContainsKey("target"))
                    {
                        task.Target = element.GetAttributeReference("target").Value;
                    }
                    if (element.Attributes.ContainsKey("member"))
                    {
                        task.Member = element.GetAttributeReference("member").Value.ToString();
                    }
                    foreach (IConfigurationElement handlerElement in element.Elements.Values)
                    {
                        if (handlerElement.Attributes.ContainsKey("handlerKey"))
                        {
                            string             handlerKey = handlerElement.GetAttributeReference("handlerKey").Value.ToString();
                            IValidationHandler handler    = validationManager.Handler(handlerKey);
                            if ("expression" == handlerKey)
                            {
                                IExpressionHandler expressionHandler           = handler as IExpressionHandler;
                                IEnumerator <IConfigurationElement> enumerator = handlerElement.Elements.Values.GetEnumerator();
                                if (enumerator.MoveNext())
                                {
                                    IConfigurationElement expressionElement = enumerator.Current;
                                    expressionHandler.Expression = (validationManager.ExpressionsManager.Token(expressionElement.GetAttributeReference("type").Value.ToString()) as IExpression);
                                    if (null == expressionHandler.Expression)
                                    {
                                        throw new InvalidOperationException("Token is not an IExpression");
                                    }
                                    expressionHandler.Expression.Make(expressionElement, validationManager.ExpressionsManager);
                                }
                            }
                            task.Handlers.Add(handler);
                        }
                    }
                    validationManager.RegisterTask(task);
                }
            }
            if (config.Sections.ContainsKey("Checks"))
            {
                foreach (IConfigurationElement element in config.Sections["Checks"].Elements.Values)
                {
                    if (element.Attributes.ContainsKey("command"))
                    {
                        string command = element.GetAttributeReference("command").Value.ToString();
                        webPart.Checks.Add(command, new List <Container.CheckDefinition>());
                        foreach (IConfigurationElement checkElement in element.Elements.Values)
                        {
                            Container.CheckDefinition check = new Container.CheckDefinition();

                            if (checkElement.Attributes.ContainsKey("error"))
                            {
                                check.Error = checkElement.GetAttributeReference("error").Value.ToString();
                            }

                            if (checkElement.Attributes.ContainsKey("milestone"))
                            {
                                check.Milestone = checkElement.GetAttributeReference("milestone").Value.ToString();
                            }

                            IEnumerator <IConfigurationElement> enumerator = checkElement.Elements.Values.GetEnumerator();
                            if (enumerator.MoveNext())
                            {
                                IConfigurationElement expressionElement = enumerator.Current;
                                IExpression           expression        = webPart.ExpressionsManager.Token(expressionElement.GetAttributeReference("type").Value.ToString()) as IExpression;
                                if (null == expression)
                                {
                                    throw new InvalidOperationException("Token is not an IExpression");
                                }

                                expression.Make(expressionElement, webPart.ExpressionsManager);
                                check.Expression = expression;
                            }
                            webPart.Checks[command].Add(check);
                        }
                    }
                }
            }
            return(null);
        }