示例#1
0
        /// <summary>
        /// 网格参数重写
        /// </summary>
        /// <param name="gridType">网格类型</param>
        /// <param name="gridParams">网格参数</param>
        /// <param name="request">请求对象</param>
        public void GridParamsSet(DataGridType gridType, GridParams gridParams, HttpRequest request = null)
        {
            Sys_GridField enameField = gridParams.GridFields.Where(x => x.Sys_FieldName == "EName").FirstOrDefault();
            int           index      = gridParams.GridFields.IndexOf(enameField);

            gridParams.GridFields.Insert(index + 1, new Sys_GridField()
            {
                Sys_FieldName = "DeptId", Sort = 3, AlignOfEnum = AlignTypeEnum.Left, Width = 0, IsVisible = false
            });
            gridParams.GridFields.Insert(index + 1, new Sys_GridField()
            {
                Sys_FieldName = "DeptName", Display = "部门", Sort = 3, AlignOfEnum = AlignTypeEnum.Left, Width = 120, IsVisible = true
            });
            gridParams.GridFields.Insert(index + 2, new Sys_GridField()
            {
                Sys_FieldName = "DutyId", Sort = 3, AlignOfEnum = AlignTypeEnum.Left, Width = 0, IsVisible = false
            });
            gridParams.GridFields.Insert(index + 2, new Sys_GridField()
            {
                Sys_FieldName = "DutyName", Display = "职务", Sort = 4, AlignOfEnum = AlignTypeEnum.Left, Width = 120, IsVisible = true
            });
        }
        public string GetEditDetailHTML(Guid?id, out bool detailTopDisplay, Guid?copyId = null, HttpRequestBase request = null)
        {
            detailTopDisplay = false;
            StringBuilder sb            = new StringBuilder();
            Sys_Module    module        = id.HasValue ? SystemOperate.GetModuleById(id.Value) : null;
            bool          overwriteFlag = module != null ? module.IsCustomerModule : true;

            if (overwriteFlag) //新增页面或者自定义模块
            {
                detailTopDisplay = true;
                sb.Append("<div title=\"模块字段\">");
                sb.Append("<div id=\"regon_\">");
                sb.Append("<table id=\"grid_\" class=\"easyui-datagrid\" data-options=\"border:false,toolbar:'#toolbar',singleSelect:true,onClickCell:OnCellClick\">");
                sb.Append("<thead>");
                sb.Append("<tr>");
                sb.Append("<th data-options=\"title:'ID',field:'Id',checkbox:true\">ID</th>");
                StringBuilder fieldTypeData = new StringBuilder("[");
                fieldTypeData.Append("{id:'varchar',text:'字符串型'},");
                fieldTypeData.Append("{id:'int',text:'整型'},");
                fieldTypeData.Append("{id:'guid',text:'Guid型'},");
                fieldTypeData.Append("{id:'bit',text:'布尔型'},");
                fieldTypeData.Append("{id:'date',text:'日期型'},");
                fieldTypeData.Append("{id:'datetime',text:'时间型'},");
                fieldTypeData.Append("{id:'decimal',text:'数值型'}");
                fieldTypeData.Append("]");
                sb.Append("<th data-options=\"title:'字段类型',field:'FieldType',width:100,align:'center',formatter:function(value,row,index){return FormatField(value,row,index,'FieldType'," + fieldTypeData + ");},editor:{type:'combobox',options:{valueField:'id',editable:false,textField:'text',data:" + fieldTypeData.ToString() + ",required:true,onSelect:OnFieldTypeSelected}}\">字段类型</th>");
                sb.Append("<th data-options=\"title:'外键模块',field:'ForeignModuleName',width:100,align:'center',editor:{type:'combobox',options:{valueField:'Name',textField:'Name',editable:true,onSelect:OnSelectForeignModule}}\">外键模块</th>");
                sb.Append("<th data-options=\"title:'字段名',field:'FieldName',width:100,align:'center',editor:{type:'textbox',options:{required:true}}\">字段名</th>");
                sb.Append("<th data-options=\"title:'字段长度',field:'FieldLen',width:100,align:'center',editor:{type:'numberbox',options:{precision:0}}\">字段长度</th>");
                sb.Append("<th data-options=\"title:'显示名称',field:'Display',width:100,align:'center',editor:{type:'textbox',options:{required:true}}\">显示名称</th>");
                sb.Append("<th data-options=\"title:'是否表单显示',field:'IsEnableForm',width:100,align:'center',formatter:function(value,row,index){return FormatField(value,row,index,'IsEnableForm');},editor:{type:'checkbox',options:{on:'1',off:'0'}}\">是否表单显示</th>");
                sb.Append("<th data-options=\"title:'控件类型',field:'ControlType',width:100,align:'center',formatter:function(value,row,index){return FormatField(value,row,index,'ControlType');},editor:{type:'combobox',options:{valueField:'id',editable:false,textField:'text',required:true}}\">控件类型</th>");
                sb.Append("<th data-options=\"title:'控件宽度',field:'ControlWidth',width:100,align:'center',editor:{type:'numberbox',options:{precision:0}}\">控件宽度</th>");
                sb.Append("<th data-options=\"title:'是否必填',field:'IsRequired',width:100,align:'center',formatter:function(value,row,index){return FormatField(value,row,index,'IsRequired');},editor:{type:'checkbox',options:{on:'1',off:'0'}}\">是否必填</th>");
                sb.Append("<th data-options=\"title:'所在行',field:'RowNum',width:100,align:'center',editor:{type:'numberbox',options:{precision:0}}\">所在行</th>");
                sb.Append("<th data-options=\"title:'所在列',field:'ColNum',width:100,align:'center',editor:{type:'numberbox',options:{precision:0}}\">所在列</th>");
                sb.Append("<th data-options=\"title:'是否列表显示',field:'IsEnableGrid',width:100,align:'center',formatter:function(value,row,index){return FormatField(value,row,index,'IsEnableGrid');},editor:{type:'checkbox',options:{on:'1',off:'0'}}\">是否列表显示</th>");
                sb.Append("<th data-options=\"title:'列头宽度',field:'HeadWidth',width:100,align:'center',editor:{type:'numberbox',options:{precision:0}}\">列头宽度</th>");
                sb.Append("<th data-options=\"title:'列排序编号',field:'HeadSort',width:100,align:'center',editor:{type:'numberbox',options:{precision:0}}\">列排序编号</th>");
                sb.Append("<th data-options=\"title:'允许搜索',field:'IsAllowGridSearch',width:100,align:'center',formatter:function(value,row,index){return FormatField(value,row,index,'IsAllowGridSearch');},editor:{type:'checkbox',options:{on:'1',off:'0'}}\">允许搜索</th>");
                sb.Append("</tr>");
                sb.Append("</thead>");
                if (module != null)
                {
                    string              modelDll    = string.Format("{0}TempModel\\{1}.dll", Globals.GetBinPath(), module.TableName);
                    Assembly            dllAssembly = Assembly.LoadFrom(modelDll);
                    Type                modelType   = dllAssembly.GetTypes().Where(x => x.Name == module.TableName).FirstOrDefault();
                    List <PropertyInfo> ps          = modelType.GetProperties().ToList();
                    sb.Append("<tbody>");
                    foreach (PropertyInfo p in ps)
                    {
                        if (CommonDefine.BaseEntityFieldsContainId.Contains(p.Name))
                        {
                            continue;
                        }
                        FieldConfigAttribute fieldAttr = (FieldConfigAttribute)Attribute.GetCustomAttribute(p, typeof(FieldConfigAttribute));
                        if (fieldAttr == null)
                        {
                            continue;
                        }
                        Sys_Field sysField = SystemOperate.GetFieldInfo(module.Id, p.Name);
                        if (sysField == null)
                        {
                            continue;
                        }
                        int    fieldLen  = 0;
                        string fieldType = "varchar";
                        if (p.PropertyType == typeof(String))
                        {
                            StringLengthAttribute stringLenAttr = (StringLengthAttribute)Attribute.GetCustomAttribute(p, typeof(StringLengthAttribute));
                            if (stringLenAttr != null)
                            {
                                fieldLen = stringLenAttr.MaximumLength;
                            }
                            else
                            {
                                fieldLen = 8000;
                            }
                        }
                        else if (p.PropertyType == typeof(Boolean) || p.PropertyType == typeof(Boolean?))
                        {
                            fieldLen  = 1;
                            fieldType = "bit";
                        }
                        else if (p.PropertyType == typeof(Int32) || p.PropertyType == typeof(Int32?))
                        {
                            fieldLen  = 4;
                            fieldType = "int";
                        }
                        else if (p.PropertyType == typeof(Guid) || p.PropertyType == typeof(Guid?))
                        {
                            fieldLen  = 36;
                            fieldType = "guid";
                        }
                        else if (p.PropertyType == typeof(Decimal) || p.PropertyType == typeof(Decimal?))
                        {
                            fieldLen  = 20;
                            fieldType = "decimal";
                        }
                        else if (p.PropertyType == typeof(DateTime) || p.PropertyType == typeof(DateTime?))
                        {
                            if (fieldAttr.ControlType == (int)ControlTypeEnum.DateBox)
                            {
                                fieldType = "date";
                            }
                            else
                            {
                                fieldType = "datetime";
                            }
                            fieldLen = 20;
                        }
                        Sys_FormField field     = SystemOperate.GetNfDefaultFormSingleField(sysField);
                        Sys_Grid      grid      = SystemOperate.GetDefaultGrid(module.Id);
                        Sys_GridField gridField = SystemOperate.GetGridFields(grid.Id, false).Where(x => x.Sys_FieldId == sysField.Id).FirstOrDefault();
                        sb.Append("<tr>");
                        sb.AppendFormat("<td>{0}</td>", sysField.Id);                                                                              //字段Id
                        sb.AppendFormat("<td>{0}</td>", fieldType);                                                                                //字段类型
                        sb.AppendFormat("<td>{0}</td>", sysField.ForeignModuleName.ObjToStr());                                                    //外键模块
                        sb.AppendFormat("<td>{0}</td>", p.Name);                                                                                   //字段名
                        sb.AppendFormat("<td>{0}</td>", fieldLen);                                                                                 //字段长度
                        sb.AppendFormat("<td>{0}</td>", sysField.Display);                                                                         //显示名称
                        sb.AppendFormat("<td>{0}</td>", field != null ? "1" : "0");                                                                //是否表单显示
                        sb.AppendFormat("<td>{0}</td>", field != null ? field.ControlType.ToString() : string.Empty);                              //控件类型
                        sb.AppendFormat("<td>{0}</td>", field == null || field.Width == 0 ? 180 : field.Width);                                    //控件宽度
                        sb.AppendFormat("<td>{0}</td>", field == null ? string.Empty : (field.IsRequired == true ? "1" : "0"));                    //是否必填
                        sb.AppendFormat("<td>{0}</td>", field != null ? field.RowNo.ToString() : string.Empty);                                    //所在行
                        sb.AppendFormat("<td>{0}</td>", field != null ? field.ColNo.ToString() : string.Empty);                                    //所在列
                        sb.AppendFormat("<td>{0}</td>", gridField != null ? "1" : "0");                                                            //是否列表显示
                        sb.AppendFormat("<td>{0}</td>", gridField != null && gridField.Width.HasValue ? gridField.Width.Value.ToString() : "120"); //列头宽度
                        sb.AppendFormat("<td>{0}</td>", gridField != null ? gridField.Sort.ToString() : string.Empty);                             //列排序编号
                        sb.AppendFormat("<td>{0}</td>", gridField != null ? (gridField.IsAllowSearch ? "1" : "0") : string.Empty);                 //允许搜索
                        sb.Append("</tr>");
                    }
                    sb.Append("</tbody>");
                }
                sb.Append("</table>");
                //网格工具栏和搜索框
                sb.Append("<div id=\"toolbar\" class=\"toolbar datagrid-toolbar\" style=\"height:27px;\">");
                sb.Append("<a id=\"btnAdd\" href=\"#\" style=\"float:left;\" class=\"easyui-linkbutton\" data-options=\"plain:true,iconCls:'eu-icon-add'\" onclick=\"AddField()\">新增</a>");
                sb.Append("<a id=\"btnDel\" href=\"#\" style=\"float:left;\" class=\"easyui-linkbutton\" data-options=\"plain:true,iconCls:'eu-p2-icon-delete2'\" onclick=\"DelField()\">删除</a>");
                sb.Append("</div>");
                sb.Append("</div>");
                sb.Append("</div>");
                sb.Append("<script type=\"text/javascript\" src=\"/Scripts/common/Grid.js\"></script>");
            }
            return(sb.ToString());
        }