Beispiel #1
0
        ///// <summary>
        ///// 设置属性
        ///// </summary>
        //protected override void SetAttributes()
        //{
        //    DataGrid control = this.ControlHost.Content as DataGrid;
        //    this.HtmlWriter.AddAttribute("dojoType", "Controls/EnhancedGrid");
        //    if (!IsPreview && !string.IsNullOrEmpty(this.ControlHost.Name))
        //    {
        //        this.HtmlWriter.AddAttribute("id", this.ControlHost.Name);
        //        this.HtmlWriter.AddAttribute("name", this.ControlHost.Name);
        //    }
        //    if (control.SingleClickEdit)
        //    {
        //        this.HtmlWriter.AddAttribute("singleClickEdit", control.SingleClickEdit.ToString().ToLower());
        //    }
        //    string pluginsStr = "pagination:{pageSizes:[],defaultPage:1,defaultPageSize:10}";
        //    this.HtmlWriter.AddAttribute("region", "center");
        //    this.HtmlWriter.AddAttribute("columnreordering", "true");
        //    this.HtmlWriter.AddAttribute("nestedsorting", "true");
        //    if (control.SelectionMode != ESelectionMode.None)
        //    {
        //        this.HtmlWriter.AddAttribute("selectionmode", control.SelectionMode.ToString().ToLower());
        //        pluginsStr += ",indirectSelection:{headerSelector:true,styles:'text-align:center;'}";
        //    }
        //    if (!this.IsPreview)
        //    {
        //        this.HtmlWriter.AddAttribute("plugins", "{" + pluginsStr + "}");
        //    }
        //    string structures = GetDataGridStructure();
        //    if (!string.IsNullOrEmpty(structures))
        //    {
        //        this.HtmlWriter.AddAttribute("structure", structures, false);
        //    }
        //    string stores = GetDataGridStore();
        //    if (!string.IsNullOrEmpty(stores))
        //    {
        //        this.HtmlWriter.AddAttribute("store", stores, false);
        //    }

        //    StringBuilder sbProps = new StringBuilder();
        //    StringBuilder returnContent = new StringBuilder();
        //    string props = control.BuildControlProps(this.ScreenDefinition, this.IsPreview, returnContent);
        //    if (!string.IsNullOrEmpty(props)) sbProps.AppendFormat("{0},", props);
        //    if (sbProps.ToString().Length > 0)
        //    {
        //        this.HtmlWriter.AddAttribute("data-dojo-props", sbProps.ToString().Substring(0, sbProps.ToString().Length - 1), false);
        //    }

        //    base.SetAttributes();
        //}

        ///// <summary>
        ///// 设置子元素
        ///// </summary>
        //protected override void SetChildElements()
        //{

        //}

        ///// <summary>
        ///// 设置DataGrid列
        ///// </summary>
        ///// <returns></returns>
        //private string GetDataGridStructure()
        //{
        //    StringBuilder sb = new StringBuilder();
        //    if (this.ControlHost.Children.Count > 0)
        //    {
        //        var content = this.ControlHost.Content as DataGrid;

        //        sb.Append("[{");
        //        sb.Append("cells:[[");
        //        string cellNumber = "{name:'序号',type:dojox.grid.cells.RowIndex,width:4},";
        //        StringBuilder cellStr = new StringBuilder();
        //        foreach (var child in this.ControlHost.Children)
        //        {
        //            StringBuilder cellContent = new StringBuilder();
        //            StringBuilder sbProps = new StringBuilder();
        //            ControlBase control = child.Content;
        //            dynamic c = control;
        //            string controlName = control.GetType().Name;

        //            cellContent.AppendFormat("name:'{0}',", child.Title);
        //            #region editable
        //            bool editable = true;
        //            DataGrid gridControl = (DataGrid)this.ControlHost.Content;
        //            if (gridControl.IsReadOnly || !gridControl.IsEnable) editable = false;
        //            if (editable)
        //            {
        //                if (control.ExistProperty("IsReadOnly"))
        //                {
        //                    if (c.IsReadOnly) editable = false;
        //                }
        //                if (editable)
        //                {
        //                    if (control.ExistProperty("IsEnable"))
        //                    {
        //                        if (!c.IsEnable) editable = false;
        //                    }
        //                }
        //            }
        //            if (controlName == "Hyperlink" || controlName == "Button") editable = false;
        //            if (editable) cellContent.AppendFormat("editable:true,");
        //            #endregion
        //            #region width
        //            if (control.ExistProperty("Width"))
        //            {
        //                if (c.Width > 0) cellContent.AppendFormat("width:{0},", c.Width.ToString());
        //            }
        //            #endregion
        //            #region title
        //            string controlTitle = child.Title == null ? "" : child.Title;
        //            #endregion
        //            if (!this.IsPreview)
        //            {
        //                StringBuilder returnContent = new StringBuilder();
        //                sbProps.AppendFormat("{0},", "context:at('rel:','VM')");
        //                string props = ControlBaseExtend.BuildControlProps(control, this.ScreenDefinition, this.IsPreview, returnContent, true);
        //                if (!string.IsNullOrEmpty(props)) sbProps.AppendFormat("{0},", props);
        //                if (returnContent.ToString().Length > 0) cellContent.Append(returnContent.ToString());
        //                if (sbProps.ToString().Length > 0) cellContent.Append("widgetProps:{" + sbProps.ToString().Substring(0, sbProps.ToString().Length - 1) + "},");
        //            }
        //            cellContent.AppendFormat("{0}", control.GetGridCellType(controlTitle));
        //            cellStr.Append("{" + cellContent.ToString() + "},");
        //        }
        //        if (cellStr.ToString().Length > 0)
        //        {
        //            string cell = cellNumber + cellStr.ToString();
        //            sb.Append(cell.ToString().Substring(0, cell.ToString().Length - 1));
        //        }
        //        sb.Append("]]");
        //        sb.Append("}]");
        //    }

        //    return sb.ToString();
        //}

        ///// <summary>
        ///// 设置DataGird的Store
        ///// </summary>
        ///// <returns></returns>
        //private string GetDataGridStore()
        //{
        //    DataGrid control = (DataGrid)this.ControlHost.Content;

        //    StringBuilder result = new StringBuilder();
        //    bool bindingDataSource = false;
        //    Dictionary<string, string> dictProperty = BuildCommonMethod.GetPropertyBindValue();
        //    if (!IsPreview && control.Bindings.Count > 0)
        //    {
        //        foreach (var item in control.Bindings)
        //        {
        //            string bindPath = item.Path == null ? "" : item.Path;
        //            string bindProperty = item.Property == null ? "" : item.Property;
        //            if (bindProperty.ToLower() == "datasource")
        //            {
        //                string property = string.Empty;
        //                if (dictProperty.ContainsKey(bindProperty))
        //                {
        //                    if (dictProperty.TryGetValue(bindProperty, out property)) bindProperty = property;
        //                }
        //                if (!string.IsNullOrEmpty(bindPath) && !string.IsNullOrEmpty(bindProperty))
        //                {
        //                    result.AppendFormat("at('rel:{0}', '{1}').direction(1),", "", bindPath);
        //                    if (bindProperty.ToLower() == "datasource") bindingDataSource = true;
        //                }
        //            }
        //        }
        //    }
        //    if (!IsPreview && control.ExistProperty("DataSource") && !bindingDataSource)
        //    {
        //        string bindPath = control.DataSource;
        //        string bindProperty = "DataSource";
        //        if (!string.IsNullOrEmpty(bindPath))
        //        {
        //            string property = string.Empty;
        //            if (dictProperty.ContainsKey(bindProperty))
        //            {
        //                if (dictProperty.TryGetValue(bindProperty, out property)) bindProperty = property;
        //            }
        //            result.AppendFormat("at('rel:{0}', '{1}').direction(1),", "", bindPath);
        //        }
        //    }

        //    return result.ToString().Length == 0 ? "" : result.ToString().Substring(0, result.Length - 1);
        //}
        #endregion

        #region 新版Grid
        /// <summary>
        /// 设置属性
        /// </summary>
        protected override void SetAttributes()
        {
            DataGrid control = this.ControlHost.Content as DataGrid;

            this.HtmlWriter.AddAttribute("dojoType", "Controls/Panel");
            string stores = GetStore();

            StringBuilder returnContent = new StringBuilder();
            string        props         = control.BuildControlProps(this.ScreenDefinition, this.IsPreview, this.PermissionData, returnContent);
            string        dojoProps     = stores + returnContent;

            if (!string.IsNullOrEmpty(dojoProps))
            {
                this.HtmlWriter.AddAttribute("data-dojo-props", dojoProps.ToString().Length == 0 ? "" : dojoProps.ToString().Substring(0, dojoProps.ToString().Length - 1), false);
            }

            base.SetAttributes();
        }
Beispiel #2
0
        /// <summary>
        /// 设置子元素
        /// </summary>
        protected override void SetChildElements()
        {
            DataGrid control = this.ControlHost.Content as DataGrid;

            this.HtmlWriter.AddAttribute("dojoType", "Controls/Dgrid/OnDemandGrid");
            if (!IsPreview && !string.IsNullOrEmpty(this.ControlHost.Name))
            {
                this.HtmlWriter.AddAttribute("id", this.ControlHost.Name);
                this.HtmlWriter.AddAttribute("name", this.ControlHost.Name);
            }

            StringBuilder sbProps       = new StringBuilder();
            StringBuilder sbConstraints = new StringBuilder();
            StringBuilder returnContent = new StringBuilder();
            string        props         = control.BuildControlProps(this.ScreenDefinition, this.IsPreview, this.PermissionData, returnContent, sbConstraints);

            if (!string.IsNullOrEmpty(props))
            {
                sbProps.AppendFormat("{0},", props);
            }
            if (control.AutoLoadData)
            {
                sbProps.AppendFormat("{0},", "autoLoadData:false");
            }
            sbProps.AppendFormat("{0},", "hiddenColoumnButton:" + control.HiddenColoumnButton.ToString().ToLower() + "");

            if (control.SelectionMode == ESelectionMode.Multiple)
            {
                sbProps.AppendFormat("{0},", "selectionMode:'multiple'");
            }
            bool remberConfig = false;

            if (!string.IsNullOrEmpty(this.ControlHost.Name))
            {
                remberConfig = true;
            }
            sbProps.AppendFormat("{0},", "remberConfig:" + remberConfig.ToString().ToLower());
            sbProps.AppendFormat("{0},", "pagingTextBox:true");
            sbProps.AppendFormat("{0},", "allowTextSelection:true");
            sbProps.AppendFormat("{0},", "allowSelectAll:true");
            sbProps.AppendFormat("{0},", "firstLastArrows:true");
            sbProps.AppendFormat("{0},", "collection:null");
            sbProps.AppendFormat("{0},", "rowsPerPage:15");
            if (!string.IsNullOrEmpty(control.FormatterRow))
            {
                string formartContent = control.FormatterRow.Replace("\r\n", "").Replace("\"", "\'").Trim();
                sbProps.Append("formatterRow:function(row,rowData){" + formartContent + "},");
            }

            string structures = GetDataGridStructure();

            if (!string.IsNullOrEmpty(structures))
            {
                sbProps.AppendFormat("{0},", structures);
            }
            if (sbProps.ToString().Length > 0)
            {
                this.HtmlWriter.AddAttribute("data-dojo-props", sbProps.ToString().Substring(0, sbProps.ToString().Length - 1), false);
            }

            this.HtmlWriter.RenderBeginTag(this.TagName);
            foreach (var child in this.ControlHost.Children)
            {
            }
            this.HtmlWriter.RenderEndTag();
        }