/// <summary>
 /// Construct DateTimeConfiguration instance from xml element.
 /// </summary>
 /// <param name="baseControlConfigurationElement"></param>
 /// <param name="xmlParser"></param>
 public DateTimeConfiguration(XmlElement baseControlConfigurationElement, XmlParser xmlParser)
     : base(baseControlConfigurationElement, xmlParser)
 {
     this.MaxValue = xmlParser.ParseDateTime(baseControlConfigurationElement, "@MaxLength", null);
     this.MinValue = xmlParser.ParseDateTime(baseControlConfigurationElement, "@MinLength", null);
     this.DefaultDate = xmlParser.ParseEnum<DefaultDateValues>(baseControlConfigurationElement, "@DefaultDate");
     this.DefaultTime = xmlParser.ParseEnum<DefaultTimeValues>(baseControlConfigurationElement, "@DefaultTime");
 }
        /// <summary>
        /// Construct ButtonPanelConfiguration instance from xml element.
        /// </summary>
        /// <param name="panelElement"></param>
        /// <param name="xmlParser"></param>
        public ButtonPanelConfiguration(XmlElement panelElement, XmlParser xmlParser)
            : base(panelElement, xmlParser)
        {
            this.ButtonAlignment = xmlParser.ParseEnum<HorizontalAlign>(panelElement, "@ButtonAlignment");

            this.Buttons = new Collection<ButtonConfiguration>();
            XmlNodeList buttonNodeList = panelElement.SelectNodes("p:Button", xmlParser.NamespaceManager);
            foreach (XmlElement buttonElement in buttonNodeList.Cast<XmlElement>())
                this.Buttons.Add(new ButtonConfiguration(buttonElement, xmlParser));
        }
        /// <summary>
        /// Construct ButtonConfiguration instance from xml element.
        /// </summary>
        /// <param name="buttonElement"></param>
        /// <param name="xmlParser"></param>
        public ButtonConfiguration(XmlElement buttonElement, XmlParser xmlParser)
        {
            this.Css = xmlParser.ParseString(buttonElement, "@Css");
            this.Text = xmlParser.ParseString(buttonElement, "@Text");
            this.ToolTip = xmlParser.ParseString(buttonElement, "@ToolTip");
            this.ImageUrl = xmlParser.ParseString(buttonElement, "@ImageUrl");
            this.CommandArgument = xmlParser.ParseString(buttonElement, "@CommandArgument");
            if(protectedCommandArguments.Contains(this.CommandArgument.ToUpperInvariant()))
                throw new ConfigurationErrorsException(@"'Delete', 'Update' and 'View' are prohibited command arguments in button configuration.");

            this.ButtonRenderType = xmlParser.ParseEnum<ButtonRenderTypes>(buttonElement, "@Type");

            this.OnClientClick = xmlParser.ParseString(buttonElement, "p:OnClientClick");

            XmlElement gridSelectionRequiredElement = buttonElement.SelectSingleNode("p:GridSelectionRequired", xmlParser.NamespaceManager) as XmlElement;
            if (gridSelectionRequiredElement != null)
            {
                this.GridSelectionRequired = true;
                this.GridSelectionRequiredWarningMessage = xmlParser.ParseString(gridSelectionRequiredElement, "@WarningMessage");
            }
        }
        /// <summary>
        /// Construct QueryFieldConfiguration instance from xml element.
        /// </summary>
        /// <param name="queryFieldControlElement"></param>
        /// <param name="xmlParser"></param>
        public QueryFieldConfiguration(XmlElement queryFieldControlElement, XmlParser xmlParser)
        {
            this.FieldName = xmlParser.ParseString(queryFieldControlElement, "@FieldName");
            this.Operator = xmlParser.ParseEnum<QueryFieldOperators>(queryFieldControlElement, "@Operator");
            this.Occupation = xmlParser.ParseInt(queryFieldControlElement, "@Occupation", -1);
            string fieldValueTypeName = xmlParser.ParseString(queryFieldControlElement, "@FieldValueType");
            if (!Kit.IsEmpty(fieldValueTypeName))
            {
                try
                {
                    this.FieldValueType = Kit.GetType(fieldValueTypeName);
                }
                catch (NotImplementedException exp)
                {
                    throw new ConfigurationErrorsException(exp.Message, exp);
                }
            }

            this.Control = BaseControlConfiguration.Create(queryFieldControlElement, xmlParser);
            this.Occupation = QueryFieldControlFactory.CalculateQueryControlOccupation(this);
        }
        /// <summary>
        /// Construct HierarchySelectorConfiguration instance from xml element.
        /// </summary>
        /// <param name="baseControlConfigurationElement"></param>
        /// <param name="xmlParser"></param>
        public HierarchySelectorConfiguration(XmlElement baseControlConfigurationElement, XmlParser xmlParser)
            : base(baseControlConfigurationElement, xmlParser)
        {
            this.Title = xmlParser.ParseString(baseControlConfigurationElement, "@Title");
            this.Cascading = xmlParser.ParseEnum<TreeNodeCheckCascadingTypes>(baseControlConfigurationElement, "@Cascading");

            XmlElement hierarchyServiceElement = baseControlConfigurationElement.SelectSingleNode("p:HierarchyService", xmlParser.NamespaceManager) as XmlElement;
            if (hierarchyServiceElement != null)
            {
                string hierarchyType = xmlParser.ParseString(hierarchyServiceElement, "@HierarchyType");
                this.ServiceUrl = string.Format(CultureInfo.InvariantCulture, "~/services/HierarchyService.svc/json/GetAllHierarchyData/{0}", hierarchyType);
                this.TextField = "Name";
                this.ValueField = "HierarchyDataId";
                this.ParentValueField = "ParentHierarchyDataId";
            }
            else
            {
                this.ServiceUrl = xmlParser.ParseString(baseControlConfigurationElement, "ExternalService/@ServiceUrl");
                this.TextField = xmlParser.ParseString(baseControlConfigurationElement, "ExternalService/@TextField");
                this.ValueField = xmlParser.ParseString(baseControlConfigurationElement, "ExternalService/@ValueField");
                this.ParentValueField = xmlParser.ParseString(baseControlConfigurationElement, "ExternalService/@ParentValueField");
            }
        }
        /// <summary>
        /// Construct DynamicDataSourceConfiguration instance from xml element.
        /// </summary>
        /// <param name="remoteDataSourceElement"></param>
        /// <param name="xmlParser"></param>
        public ComboBoxDynamicDataSourceConfiguration(XmlElement remoteDataSourceElement, XmlParser xmlParser)
        {
            this.Url = xmlParser.ParseString(remoteDataSourceElement, "@Url");
            this.Root = xmlParser.ParseString(remoteDataSourceElement, "@Root");
            this.TextField = xmlParser.ParseString(remoteDataSourceElement, "@TextField");
            this.ValueField = xmlParser.ParseString(remoteDataSourceElement, "@ValueField");
            this.QueryParam = xmlParser.ParseString(remoteDataSourceElement, "@QueryParam");
            this.Method = xmlParser.ParseEnum<HttpMethods>(remoteDataSourceElement, "@Method");
            this.Proxy = xmlParser.ParseEnum<DataProxyTypes>(remoteDataSourceElement, "@Proxy");
            if (string.IsNullOrEmpty(this.QueryParam))
                this.QueryParam = "query";

            this.Params = new Collection<ComboBoxDynamicDataSourceParamConfiguration>();
            XmlNodeList paramNodes = remoteDataSourceElement.SelectNodes("p:Param", xmlParser.NamespaceManager);
            foreach (XmlNode paramNode in paramNodes)
                this.Params.Add(new ComboBoxDynamicDataSourceParamConfiguration(paramNode as XmlElement, xmlParser));

            XmlElement xtemplateElement = remoteDataSourceElement.SelectSingleNode("p:XTemplate", xmlParser.NamespaceManager) as XmlElement;
            if (xtemplateElement != null)
            {
                this.XTemplate = xtemplateElement.InnerXml;
                this.ItemSelector = xmlParser.ParseString(xtemplateElement, "@ItemSelector");
            }
        }
        /// <summary>
        /// Construct GridView Configuration
        /// </summary>
        /// <param name="gridViewElement"></param>
        /// <param name="xmlParser"></param>
        public GridViewPanelConfiguration(XmlElement gridViewElement, XmlParser xmlParser)
            : base(gridViewElement, xmlParser)
        {
            this.EntityName = xmlParser.ParseString(gridViewElement, "@EntityName");
            this.PrimaryKeyFieldName = xmlParser.ParseString(gridViewElement, "@PrimaryKeyFieldName");
            this.PageSize = xmlParser.ParseInt(gridViewElement, "@PageSize", 25);
            this.EnabledCheckBoxField = xmlParser.ParseBoolean(gridViewElement, "@EnabledCheckBoxField", false);
            this.ExecuteQueryWhenLoaded = xmlParser.ParseBoolean(gridViewElement, "@ExecuteQueryWhenLoaded", true);
            this.EnabledColumnMove = xmlParser.ParseBoolean(gridViewElement, "@EnabledColumnMove", false);
            this.EnabledColumnResize = xmlParser.ParseBoolean(gridViewElement, "@EnabledColumnResize", false);
            this.Height = xmlParser.ParseInt(gridViewElement, "@Height", 500);
            this.DefaultSortField = xmlParser.ParseString(gridViewElement, "@DefaultSortField");
            this.DefaultSortDirection = xmlParser.ParseEnum<GridViewFieldSortDirection>(gridViewElement, "@DefaultSortDirection");

            XmlElement viewButtomElement = gridViewElement.SelectSingleNode("p:ViewButton", xmlParser.NamespaceManager) as XmlElement;
            if (viewButtomElement != null)
                this.ViewButton = new GridViewRowButtonConfiguration(viewButtomElement, xmlParser);

            XmlElement editButtomElement = gridViewElement.SelectSingleNode("p:EditButton", xmlParser.NamespaceManager) as XmlElement;
            if (editButtomElement != null)
                this.EditButton = new GridViewRowButtonConfiguration(editButtomElement, xmlParser);

            XmlElement deleteButtomElement = gridViewElement.SelectSingleNode("p:DeleteButton", xmlParser.NamespaceManager) as XmlElement;
            if (deleteButtomElement != null)
                this.DeleteButton = new GridViewRowButtonConfiguration(deleteButtomElement, xmlParser);

            this.Fields = new Collection<GridViewFieldConfiguration>();
            XmlNodeList fieldNodes = gridViewElement.SelectNodes("p:Fields/p:Field", xmlParser.NamespaceManager);
            foreach (XmlElement fieldElement in fieldNodes.Cast<XmlElement>())
                this.Fields.Add(new GridViewFieldConfiguration(fieldElement, xmlParser));

            XmlElement rowViewElement = gridViewElement.SelectSingleNode("p:Fields/p:RowView", xmlParser.NamespaceManager) as XmlElement;
            if (rowViewElement != null)
                this.RowView = new GridViewFieldRowViewConfiguration(rowViewElement, xmlParser);
        }
        /// <summary>
        /// Construct GridViewFieldConfiguration instance.
        /// </summary>
        /// <param name="gridViewFieldElement"></param>
        /// <param name="xmlParser"></param>
        public GridViewFieldConfiguration(XmlElement gridViewFieldElement, XmlParser xmlParser)
        {
            this.FieldName = xmlParser.ParseString(gridViewFieldElement, "@FieldName");
            this.HeaderText = xmlParser.ParseString(gridViewFieldElement, "@HeaderText");
            this.SortingFieldName = xmlParser.ParseString(gridViewFieldElement, "@SortingFieldName");
            this.Sortable = xmlParser.ParseBoolean(gridViewFieldElement, "@Sortable", true);
            this.Resizable = xmlParser.ParseBoolean(gridViewFieldElement, "@Resizble", true);
            this.Css = xmlParser.ParseString(gridViewFieldElement, "@Css");
            this.Width = xmlParser.ParseInt(gridViewFieldElement, "@Width", null);
            this.ExtJsRenderer = xmlParser.ParseString(gridViewFieldElement, "p:ExtJs-Renderer");
            this.Align = xmlParser.ParseEnum<HorizontalAlign>(gridViewFieldElement, "p:Align");
            this.Hidden = xmlParser.ParseBoolean(gridViewFieldElement, "@Hidden", false);

            foreach (XmlElement transformNode in gridViewFieldElement.ChildNodes)
            {
                XmlElement transformElement = transformNode as XmlElement;
                if (transformElement != null && SUPPORT_TRANSFORM_TYPES.Contains(transformElement.LocalName))
                    this.Transformer = new GridViewFieldValueTransformConfiguration(transformElement, xmlParser);
            }
        }
 /// <summary>
 /// Construct GeneralButtonConfiguration instance from xml element.
 /// </summary>
 /// <param name="buttonElement"></param>
 /// <param name="xmlParser"></param>
 public GeneralButtonConfiguration(XmlElement buttonElement, XmlParser xmlParser)
     : base(buttonElement, xmlParser)
 {
     this.Action = xmlParser.ParseEnum<ButtonActions>(buttonElement, "@Action");
 }
 /// <summary>
 /// Construct TextBoxConfiguration instance from xml element.
 /// </summary>
 /// <param name="baseControlConfigurationElement"></param>
 /// <param name="xmlParser"></param>
 public TextBoxConfiguration(XmlElement baseControlConfigurationElement, XmlParser xmlParser)
     : base(baseControlConfigurationElement, xmlParser)
 {
     XmlElement textboxElement = baseControlConfigurationElement;
     this.MaxLength = xmlParser.ParseInt(textboxElement, "@MaxLength", null);
     this.MinLength = xmlParser.ParseInt(textboxElement, "@MinLength", null);
     this.ValidationType = xmlParser.ParseEnum<TextBoxValidationTypes>(textboxElement, "@ValidationType");
 }