public string GenerateVM(string name) { var rv = GetResource($"{name}.txt").Replace("$modelnamespace$", ModelNS).Replace("$vmnamespace$", VMNs).Replace("$modelname$", ModelName).Replace("$area$", $"{Area??""}"); if (name == "Searcher" || name == "BatchVM") { string prostring = ""; string initstr = ""; Type modelType = Type.GetType(SelectedModel); List <FieldInfo> pros = null; if (name == "Searcher") { pros = FieldInfos.Where(x => x.IsSearcherField == true).ToList(); } if (name == "BatchVM") { pros = FieldInfos.Where(x => x.IsBatchField == true).ToList(); } foreach (var pro in pros) { if (pro.RelatedField != null) { var subtype = Type.GetType(pro.RelatedField); if (typeof(TopBasePoco).IsAssignableFrom(subtype) == false || subtype == typeof(FileAttachment)) { continue; } var fname = "All" + pro.FieldName.Substring(0, pro.FieldName.Length - 2) + "s"; prostring += $@" public List<ComboSelectListItem> {fname} {{ get; set; }}"; initstr += $@" {fname} = DC.Set<{subtype.Name}>().GetSelectListItems(LoginUserInfo.DataPrivileges, null, y => y.{pro.SubField});"; } var proType = modelType.GetProperty(pro.FieldName); var display = proType.GetCustomAttribute <DisplayAttribute>(); if (display != null) { prostring += $@" [Display(Name = ""{display.Name}"")]"; } string typename = proType.PropertyType.Name; if (proType.PropertyType.IsNullable()) { typename = proType.PropertyType.GetGenericArguments()[0].Name + "?"; } prostring += $@" public {typename} {proType.Name} {{ get; set; }}"; } rv = rv.Replace("$pros$", prostring).Replace("$init$", initstr); rv = GetRelatedNamespace(pros, rv); } if (name == "ListVM") { string headerstring = ""; string selectstring = ""; string wherestring = ""; string subprostring = ""; string formatstring = ""; var pros = FieldInfos.Where(x => x.IsListField == true).ToList(); foreach (var pro in pros) { if (pro.RelatedField == null) { headerstring += $@" this.MakeGridHeader(x => x.{pro.FieldName}),"; selectstring += $@" {pro.FieldName} = x.{pro.FieldName},"; } else { var subtype = Type.GetType(pro.RelatedField); if (subtype == typeof(FileAttachment)) { headerstring += $@" this.MakeGridHeader(x => x.{pro.FieldName}).SetFormat({pro.FieldName}Format),"; selectstring += $@" {pro.FieldName} = x.{pro.FieldName},"; formatstring += GetResource("HeaderFormat.txt").Replace("$modelname$", ModelName).Replace("$field$", pro.FieldName); } else { var subpro = subtype.GetProperty(pro.SubField); string subtypename = subpro.PropertyType.Name; if (subpro.PropertyType.IsNullable()) { subtypename = subpro.PropertyType.GetGenericArguments()[0].Name + "?"; } var subdisplay = subpro.GetCustomAttribute <DisplayAttribute>(); headerstring += $@" this.MakeGridHeader(x => x.{pro.SubField + "_view"}),"; selectstring += $@" {pro.SubField + "_view"} = x.{pro.FieldName.Substring(0, pro.FieldName.Length - 2)}.{pro.SubField},"; if (subdisplay?.Name != null) { subprostring += $@" [Display(Name = ""{subdisplay.Name}"")]"; subprostring += $@" public {subtypename} {pro.SubField + "_view"} {{ get; set; }}"; } } } } var wherepros = FieldInfos.Where(x => x.IsSearcherField == true).ToList(); Type modelType = Type.GetType(SelectedModel); foreach (var pro in wherepros) { var proType = modelType.GetProperty(pro.FieldName).PropertyType; if (proType == typeof(string)) { wherestring += $@" .CheckContain(Searcher.{pro.FieldName}, x=>x.{pro.FieldName})"; } else { wherestring += $@" .CheckEqual(Searcher.{pro.FieldName}, x=>x.{pro.FieldName})"; } } rv = rv.Replace("$headers$", headerstring).Replace("$where$", wherestring).Replace("$select$", selectstring).Replace("$subpros$", subprostring).Replace("$format$", formatstring); rv = GetRelatedNamespace(pros, rv); } if (name == "CrudVM") { string prostr = ""; string initstr = ""; string includestr = ""; var pros = FieldInfos.Where(x => x.IsFormField == true && x.RelatedField != null).ToList(); foreach (var pro in pros) { var subtype = Type.GetType(pro.RelatedField); if (typeof(TopBasePoco).IsAssignableFrom(subtype) == false || subtype == typeof(FileAttachment)) { continue; } var fname = "All" + pro.FieldName.Substring(0, pro.FieldName.Length - 2) + "s"; prostr += $@" public List<ComboSelectListItem> {fname} {{ get; set; }}"; initstr += $@" {fname} = DC.Set<{subtype.Name}>().GetSelectListItems(LoginUserInfo.DataPrivileges, null, y => y.{pro.SubField});"; includestr += $@" SetInclude(x => x.{pro.FieldName.Substring(0, pro.FieldName.Length - 2)});"; } rv = rv.Replace("$pros$", prostr).Replace("$init$", initstr).Replace("$include$", includestr); rv = GetRelatedNamespace(pros, rv); } if (name == "ImportVM") { string prostring = ""; string initstr = ""; Type modelType = Type.GetType(SelectedModel); List <FieldInfo> pros = FieldInfos.Where(x => x.IsImportField == true).ToList(); foreach (var pro in pros) { if (pro.RelatedField != null) { var subtype = Type.GetType(pro.RelatedField); if (typeof(TopBasePoco).IsAssignableFrom(subtype) == false || subtype == typeof(FileAttachment)) { continue; } initstr += $@" {pro.FieldName + "_Excel"}.DataType = ColumnDataType.ComboBox; {pro.FieldName + "_Excel"}.ListItems = DC.Set<{subtype.Name}>().GetSelectListItems(LoginUserInfo.DataPrivileges, null, y => y.{pro.SubField});"; } var proType = modelType.GetProperty(pro.FieldName); var display = proType.GetCustomAttribute <DisplayAttribute>(); if (display != null) { prostring += $@" [Display(Name = ""{display.Name}"")]"; } prostring += $@" public ExcelPropety {pro.FieldName + "_Excel"} = ExcelPropety.CreateProperty<{ModelName}>(x => x.{pro.FieldName});"; } rv = rv.Replace("$pros$", prostring).Replace("$init$", initstr); rv = GetRelatedNamespace(pros, rv); } return(rv); }
public string GenerateView(string name) { var rv = GetResource($"{name}.txt").Replace("$vmnamespace$", VMNs).Replace("$modelname$", ModelName); if (name == "CreateView" || name == "EditView" || name == "DeleteView" || name == "DetailsView" || name == "BatchEditView") { StringBuilder fieldstr = new StringBuilder(); string pre = ""; List <FieldInfo> pros = null; if (name == "BatchEditView") { pros = FieldInfos.Where(x => x.IsBatchField == true).ToList(); pre = "LinkedVM"; } else { pros = FieldInfos.Where(x => x.IsFormField == true).ToList(); pre = "Entity"; } Type modelType = Type.GetType(SelectedModel); fieldstr.Append(Environment.NewLine); fieldstr.Append(@"<wt:row items-per-row=""ItemsPerRowEnum.Two"">"); fieldstr.Append(Environment.NewLine); foreach (var item in pros) { if (name == "DeleteView" || name == "DetailsView") { if (item.RelatedField != null && item.SubField != "`file") { fieldstr.Append($@"<wt:display field=""{pre}.{item.FieldName.Substring(0, item.FieldName.Length - 2)}.{item.SubField}"" />"); } else { fieldstr.Append($@"<wt:display field=""{pre}.{item.FieldName}"" />"); } } else { if (item.RelatedField != null) { if (item.SubField == "`file") { fieldstr.Append($@"<wt:upload field=""{pre}.{item.FieldName}"" />"); } else { var fname = "All" + item.FieldName.Substring(0, item.FieldName.Length - 2) + "s"; if (name == "BatchEditView") { fname = "LinkedVM." + fname; } fieldstr.Append($@"<wt:combobox field=""{pre}.{item.FieldName}"" items=""{fname}""/>"); } } else { var proType = modelType.GetProperty(item.FieldName).PropertyType; Type checktype = proType; if (proType.IsNullable()) { checktype = proType.GetGenericArguments()[0]; } if (checktype == typeof(bool) || checktype.IsEnum()) { fieldstr.Append($@"<wt:combobox field=""{pre}.{item.FieldName}"" />"); } else if (checktype.IsPrimitive || checktype == typeof(string)) { fieldstr.Append($@"<wt:textbox field=""{pre}.{item.FieldName}"" />"); } else if (checktype == typeof(DateTime)) { fieldstr.Append($@"<wt:datetime field=""{pre}.{item.FieldName}"" />"); } } } fieldstr.Append(Environment.NewLine); } fieldstr.Append("</wt:row>"); rv = rv.Replace("$fields$", fieldstr.ToString()); } if (name == "ListView") { StringBuilder fieldstr = new StringBuilder(); var pros = FieldInfos.Where(x => x.IsSearcherField == true).ToList(); Type modelType = Type.GetType(SelectedModel); fieldstr.Append(Environment.NewLine); fieldstr.Append(@"<wt:row items-per-row=""ItemsPerRowEnum.Three"">"); fieldstr.Append(Environment.NewLine); foreach (var item in pros) { if (item.RelatedField != null) { var fname = "All" + item.FieldName.Substring(0, item.FieldName.Length - 2) + "s"; fieldstr.Append($@"<wt:combobox field=""Searcher.{item.FieldName}"" items=""Searcher.{fname}"" empty-text=""全部"" />"); } else { var proType = modelType.GetProperty(item.FieldName).PropertyType; Type checktype = proType; if (proType.IsNullable()) { checktype = proType.GetGenericArguments()[0]; } if (checktype.IsPrimitive || checktype == typeof(string)) { fieldstr.Append($@"<wt:textbox field=""Searcher.{item.FieldName}"" />"); } if (checktype == typeof(DateTime)) { fieldstr.Append($@"<wt:datetime field=""Searcher.{item.FieldName}"" />"); } if (checktype.IsEnum()) { fieldstr.Append($@"<wt:combobox field=""Searcher.{item.FieldName}"" empty-text=""全部"" />"); } } fieldstr.Append(Environment.NewLine); } fieldstr.Append($@"</wt:row>"); rv = rv.Replace("$fields$", fieldstr.ToString()); } return(rv); }
public string GenerateReactView(string name) { var rv = GetResource($"{name}.txt", "Spa.React.views") .Replace("$modelname$", ModelName.ToLower()); Type modelType = Type.GetType(SelectedModel); if (name == "table") { StringBuilder fieldstr = new StringBuilder(); var pros = FieldInfos.Where(x => x.IsListField == true).ToList(); fieldstr.Append(Environment.NewLine); for (int i = 0; i < pros.Count; i++) { var item = pros[i]; string label = modelType.GetProperty(item.FieldName).GetPropertyDisplayName(); string render = "columnsRender"; if (string.IsNullOrEmpty(item.RelatedField) == false) { var subtype = Type.GetType(item.RelatedField); if (subtype == typeof(FileAttachment)) { render = "columnsRenderImg"; } } fieldstr.Append($@"{{ dataIndex: ""{item.FieldName}"", title: ""{label}"", render: {render} }}"); if (i < pros.Count - 1) { fieldstr.Append(","); } fieldstr.Append(Environment.NewLine); } return(rv.Replace("$columns$", fieldstr.ToString())); } if (name == "models") { StringBuilder fieldstr = new StringBuilder(); var pros = FieldInfos.Where(x => x.IsFormField == true).ToList(); for (int i = 0; i < pros.Count; i++) { var item = pros[i]; string label = modelType.GetProperty(item.FieldName).GetPropertyDisplayName(); if (string.IsNullOrEmpty(item.RelatedField) == false) { var subtype = Type.GetType(item.RelatedField); if (item.SubField == "`file") { fieldstr.Append($@"{item.FieldName}: <UploadImg />"); } else { fieldstr.Append($@"{item.FieldName}: <Select placeholder=""{label}"" showArrow allowClear></Select>"); } } else { var proType = modelType.GetProperty(item.FieldName).PropertyType; Type checktype = proType; if (proType.IsNullable()) { checktype = proType.GetGenericArguments()[0]; } if (checktype == typeof(bool) || checktype.IsEnum()) { fieldstr.Append($@"{item.FieldName}: <Switch checkedChildren={{<Icon type=""check"" />}} unCheckedChildren={{<Icon type=""close"" />}} />"); } else if (checktype.IsPrimitive || checktype == typeof(string)) { fieldstr.Append($@"{item.FieldName}: <Input placeholder=""请输入 {label}"" />"); } else if (checktype == typeof(DateTime)) { fieldstr.Append($@"{item.FieldName}: <Input placeholder=""请输入 {label}"" />"); } } if (i < pros.Count - 1) { fieldstr.Append(","); } fieldstr.Append(Environment.NewLine); } return(rv.Replace("$fields$", fieldstr.ToString())); } if (name == "search") { StringBuilder fieldstr = new StringBuilder(); var pros = FieldInfos.Where(x => x.IsSearcherField == true).ToList(); for (int i = 0; i < pros.Count; i++) { var item = pros[i]; string label = modelType.GetProperty(item.FieldName).GetPropertyDisplayName(); fieldstr.Append($@" <Form.Item label=""{label}"" {{...formItemLayout}}> {{getFieldDecorator('{item.FieldName}', {{ initialValue: Store.searchParams['{item.FieldName}'] }})(Models.{item.FieldName})}} </Form.Item> "); fieldstr.Append(Environment.NewLine); } return(rv.Replace("$fields$", fieldstr.ToString())); } if (name == "details") { StringBuilder addfield = new StringBuilder(); StringBuilder editfield = new StringBuilder(); StringBuilder detailfield = new StringBuilder(); var pros = FieldInfos.Where(x => x.IsFormField == true).ToList(); for (int i = 0; i < pros.Count; i++) { var item = pros[i]; var property = modelType.GetProperty(item.FieldName); string label = property.GetPropertyDisplayName(); bool isrequired = property.IsPropertyRequired(); string rules = "rules: []"; if (isrequired == true) { rules = $@"rules: [{{ ""required"": true, ""message"": ""{label}不能为空"" }}]"; } if (string.IsNullOrEmpty(item.RelatedField) == false && item.SubField == "`file") { addfield.Append($@" <InfoShellCol span={{24}}> <Form.Item label=""{label}"" {{...formItemLayoutRow}}> {{getFieldDecorator('{item.FieldName}', {{ }})(Models.{item.FieldName})}} </Form.Item > </InfoShellCol> "); editfield.Append($@" <InfoShellCol span={{24}}> <Form.Item label=""{label}"" {{...formItemLayoutRow}}> {{getFieldDecorator('{item.FieldName}', {{ initialValue: details['{item.FieldName}'] }})(Models.{item.FieldName})}} </Form.Item > </InfoShellCol> "); detailfield.Append($@" <InfoShellCol span={{24}}> <Form.Item label=""{label}"" {{...formItemLayoutRow}}> <span> <ToImg fileID={{details['{item.FieldName}']}} /> </span> </Form.Item > </InfoShellCol> "); } else { addfield.Append($@" <Form.Item label=""{label}"" {{...formItemLayout}}> {{getFieldDecorator('{item.FieldName}', {{ {rules} }})(Models.{item.FieldName})}} </Form.Item> "); editfield.Append($@" <Form.Item label=""{label}"" {{...formItemLayout}}> {{getFieldDecorator('{item.FieldName}', {{ {rules}, initialValue: toValues(details['{item.FieldName}']) }})(Models.{item.FieldName})}} </Form.Item> "); detailfield.Append($@" <Form.Item label=""{label}"" {{...formItemLayout}}> <span>{{toValues(details['{item.FieldName}'], ""span"")}}</span> </Form.Item> "); } addfield.Append(Environment.NewLine); editfield.Append(Environment.NewLine); detailfield.Append(Environment.NewLine); } return(rv.Replace("$addfields$", addfield.ToString()).Replace("$editfields$", editfield.ToString()).Replace("$detailfields$", detailfield.ToString())); } return(rv); }