/// <summary> /// 新增 /// </summary> /// <param name="entity"></param> /// <param name="array"></param> public void Add(ModelDto entity, int[] array) { using (_unitOfWork) { var info = AutoMapperHelper.Signle <ModelDto, Model>(entity); var repository = _unitOfWork.Repository <Model>(); var modelFieldRepository = _unitOfWork.Repository <ModelField>(); foreach (var item in array) { var role = new ModelField { ModelFieldId = item }; modelFieldRepository.Attach(role); info.ModelFields.Add(role); } repository.Add(info); _unitOfWork.Commit(); } }
private void RenderSimpleField(ModelField field) { _generator.AppendLine($"Field(") .IncreaseIndentation() .AppendLine($"typeof({CsharpGenerator.Type(field.ResolvedType, false)}).GetGraphTypeFromType({field.Null.ToString().ToLower()}),") .AppendLine($"\"{field.Name.Camelize()}\",") .AppendLine($"@\"{field.Description}\","); if (field.ResolvedType.FieldType == FieldType.DateTime) { _generator.Append($"resolve: ctx => ctx.Source.{field.Name.Pascalize()}"); if (field.Null) { _generator.Append("?."); } else { _generator.Append("."); } _generator.AppendLine("UtcDateTime"); } else { _generator.AppendLine($"resolve: ctx => ctx.Source.{field.Name.Pascalize()}"); } _generator.DecreaseIndentation() .AppendLine(");"); }
private void RenderRequiredAttribute(ModelField field) { if (!field.Null) { _generator.AppendLine("[Required]"); } }
private void RenderKeyAttribute(ModelField field) { if (field.PrimaryKey && field.Model.HasSimplePrimaryKey) { _generator.AppendLine("[Key]"); } }
public ActionResult AddColumn() { Store store = this.GetCmp<Store>("Store1"); Ext.Net.GridPanel grid = this.GetCmp<Ext.Net.GridPanel>("GridPanel1"); ModelField field = new ModelField("pctChange", ModelFieldType.Float); store.AddField(field, 3); store.LoadData(Companies.GetAllCompanies()); Column col = new Column(); col.ID = "pctChangeColumn"; col.Text = "Change %"; col.Width = 75; col.Sortable = true; col.DataIndex = "pctChange"; col.Renderer.Fn = "pctChange"; ComboBox cb = new ComboBox() { ID = "ComboBox1" }; cb.Items.Add(new Ext.Net.ListItem("1", "1")); cb.Items.Add(new Ext.Net.ListItem("2", "2")); cb.Items.Add(new Ext.Net.ListItem("3", "3")); col.Editor.Add(cb); grid.AddColumn(col); return this.Direct(); }
public void CopyTo(ModelField field, Model model) { field.Apply(this); if (this.IDProperty) { model.IDProperty = field.Name; } if (this.CustomSortHandler != null) { field.CustomSortType.Fn = this.CustomSortHandler; } if (this.SerializeHandler != null) { field.Serialize.Fn = this.SerializeHandler; } if (this.ConvertHandler != null) { field.Convert.Fn = this.ConvertHandler; } if (this.DefaultValue != null) { field.DefaultValue = TokenUtils.RawWrap(JSON.Serialize(this.DefaultValue)); } }
public void CopyTo(ModelField field, Model model) { field.Apply(this); if (this.IDProperty) { model.IDProperty = field.Name; } if (this.CustomSortHandler != null) { field.CustomSortType.Fn = this.CustomSortHandler; } if (this.SerializeHandler != null) { field.Serialize.Fn = this.SerializeHandler; } if (this.ConvertHandler != null) { field.Convert.Fn = this.ConvertHandler; } if (this.DefaultValue != null) { field.DefaultValue = TokenUtils.RawWrap(JSON.Serialize(this.DefaultValue)); } }
/// <summary> /// 初始化自动增加的隐藏项(主键项或删除标识项) /// </summary> /// <param name="prefix"></param> /// <param name="key"></param> /// <param name="havecount"></param> /// <param name="grid"></param> private void IniAddGridColumn(string prefix, string key, int havecount, Ext.Net.GridPanel grid) { Model model = grid.GetStore().ModelInstance; if (!string.IsNullOrWhiteSpace(key)) { bool isExist = false; foreach (GridColumn column in uiHelper.Select.MainGrid.Columns) { if (key.Equals(column.ColumnName, StringComparison.CurrentCultureIgnoreCase)) { column.ColumnName = key; isExist = true; break; } } if (!isExist) { GridColumn column = new GridColumn(); column.Caption = key; column.ColumnName = key; column.IsShow = false; ModelField mField = new ModelField(); mField.Name = column.ColumnName; model.Fields.Add(mField); if (column.IsShow) { CellCommandColumn cell = IniGridColumn(prefix, column); grid.ColumnModel.Columns.Insert(grid.ColumnModel.Columns.Count - havecount, cell); } } } }
public virtual IEnumerable <ModelField> CreateModelFields() { if (HasChildren) { return(new ModelField[0]); } if (CreateModelFieldsHandler != null) { return(CreateModelFieldsHandler(this)); } var modelField = new ModelField(ColumnNameIndexOriginal, ModelFieldType) { ServerMapping = ServerMapping, UseNull = UseNull }; if (string.IsNullOrEmpty(ServerMappingRefValue)) { return new[] { modelField, } } ; return(new[] { modelField, new ModelField(ColumnNameIndexRefValue, ModelFieldTypeRefValue) { ServerMapping = ServerMappingRefValue, UseNull = UseNull } }); }
private void RenderForeignKey(ModelField field) { _generator.AppendLine($"Field<{field.ForeignKey.RefersTo.Model.Name.Pascalize()}Type>(\"{field.AccessorName.Camelize()}\", @\"{field.Description}\", resolve: ctx => ") .BeginBlock() .AppendLine($"var schemaContext = ({_model.Project.Name.Pascalize()}Schema.Context)ctx.UserContext;") .AppendLine($"return schemaContext.Database.{field.ForeignKey.RefersTo.Model.Name.Pascalize().Pluralize()}.Where(x => x.{field.ForeignKey.RefersTo.Name.Pascalize()} == ctx.Source.{field.Name.Pascalize()}).FirstOrDefault();") .EndBlock("});"); }
void CopyAttributesFrom(ModelField source, ModelField target) { target.DefaultValue = source.DefaultValue; target.IsFixedLength = source.IsFixedLength; target.IsUnicode = source.IsUnicode; target.MaxLength = source.MaxLength; target.Nullable = source.Nullable; target.Type = source.Type; }
private string FieldTypeToDb(ModelField field) { switch (field.ResolvedType.FieldType) { case FieldType.Date: return("date"); } return(null); }
public void InsertUpdateTestUpdate() { var results = ModelField.InsertUpdate(MockDb.Object, new ModelField() { ModelId = 1 }); Assert.IsTrue(results.Success); }
private void RenderForeignKey(ModelField field) { _generator.AppendLine($"/// <summary>") .AppendLine($"/// Gets or sets {field.Description}") .AppendLine($"/// /summary>") .AppendLine($"[ForeignKey(nameof({field.Name.Pascalize()}))]") .AppendLine($"public virtual {field.ForeignKey.RefersTo.Model.Name.Pascalize()} {field.AccessorName.Pascalize()} {{ get; set; }}") .EnsureEmptyLine(); }
private void RenderField(ModelField field) { _generator.AppendLine($"/// <summary>") .AppendLine($"/// Gets or sets {field.Description}") .AppendLine($"/// /summary>"); RenderAttributes(field); _generator.AppendLine($"public {CsharpGenerator.Type(field.ResolvedType, field.Null)} {field.Name.Pascalize()} {{ get; set; }}") .EnsureEmptyLine(); }
private void AddField(ModelField field) { if (X.IsAjaxRequest) { this.Store1.AddField(field); } else { this.Store1.Model[0].Fields.Add(field); } }
private void RenderColumnAttribute(ModelField field) { _generator.Append($"[Column(\"{field.Name.Underscore()}\""); var dbType = FieldTypeToDb(field); if (dbType != null) { _generator.Append($", TypeName = \"{dbType}\""); } _generator.AppendLine(")]"); }
public void AddModelFields(ModelFieldCollection fields) { foreach (var column in Columns) { var field = new ModelField(column.ColumnName); if (!string.IsNullOrEmpty(column.ServerMaping)) { field.ServerMapping = ServerMappingPerfix + column.ServerMaping; } fields.Add(field); } }
public static FieldTypeInfo Parse(ModelField field) { return(new FieldTypeInfo { Type = field.Type, IsUnicode = field.IsUnicode, IsFixedLength = field.IsFixedLength, IsIdentity = field.IsIdentity, Nullable = field.Nullable, MaxLength = field.MaxLength }); }
public void BuildStore(bool isAutoLoad) { JsonReader reader = new JsonReader { Root = "d", TotalProperty = "total", }; AjaxProxy proxy = new AjaxProxy { Url = ProxyUrl, Reader = { reader }, Json = true, ActionMethods = { Read = HttpMethod.POST }, ExtraParams = { new Ext.Net.Parameter { Name = "DocumentType", Value = DocumentType, Mode = ParameterMode.Value }, new Ext.Net.Parameter { Name = "DocumentNo", Value = DocumentNo, Mode = ParameterMode.Value }, new Ext.Net.Parameter { Name = "CurCompany", Value = CurCompany, Mode = ParameterMode.Value }, } }; Model model = new Model(); foreach (LookupFormatData d in dataTemplate) { ModelField mf = d.Type == ModelFieldType.Auto ? new ModelField(d.FieldName) : new ModelField(d.FieldName, d.Type); if (d.Type == ModelFieldType.Date) { mf.DateFormat = "M$"; //mf.Convert.Handler = @"if(value == '\/Date(-62135596800000)\/') { return null; }else { var date = new Date(parseInt(value.substr(6))); return date; } "; } model.Fields.Add(mf); } this.Store.Add(new Ext.Net.Store { Proxy = { proxy }, Model = { model }, AutoLoad = true, RemotePaging = true, WarningOnDirty = false }); }
public void FieldManipulatorByAlgorithm(ModelField ModelField) { int[,] RecountedField = new int[ModelField.X, ModelField.Y]; int Summ; for (int i = 0; i < ModelField.X; i++) { for (int j = 0; j < ModelField.Y; j++) { if (i == 0 || i == ModelField.X - 1 || j == 0 || j == ModelField.Y - 1) { RecountedField[i, j] = 0; } else { Summ = 0; for (int k = i - 1; k < i + 2; k++) { for (int l = j - 1; l < j + 2; l++) { Summ += ModelField.ReadSquareValueByCoordinate(k, l); } } if (ModelField.ReadSquareValueByCoordinate(i, j) == 0 && Summ == 3) { RecountedField[i, j] = 1; } else if (ModelField.ReadSquareValueByCoordinate(i, j) == 1 && (Summ == 3 || Summ == 4)) { RecountedField[i, j] = 1; } else if (ModelField.ReadSquareValueByCoordinate(i, j) == 1 && (Summ < 3 || Summ > 4)) { RecountedField[i, j] = 0; } } } } for (int i = 0; i < ModelField.X; i++) { for (int j = 0; j < ModelField.Y; j++) { ModelField.SetSquareValueOnPGByCoordinate(i, j, ModelField.ReadSquareValueByCoordinateOnLastGen(i, j)); ModelField.SetSquareValueOnLGByCoordinate(i, j, ModelField.ReadSquareValueByCoordinate(i, j)); ModelField.SetSquareValueByCoordinate(i, j, RecountedField[i, j]); } } ModelField.Generation++; }
public async Task <HandleResult> FieldEdit([FromBody] ModelField model) { if (model.Id <= 0) { if (model.ModelNum.IsEmpty()) { return(HandleResult.Error("请选择模型")); } if (model.Name.IsEmpty()) { return(HandleResult.Error("请填写名称")); } } var isUpdate = model.Id > 0; var info = isUpdate ? await _modelFieldService.GetById(model.Id) : new ModelField(); if (info == null) { return(HandleResult.Error("无效数据")); } info.Init(); if (info.Id <= 0) { info.ModelNum = model.ModelNum; info.Name = model.Name; info.OptionType = model.OptionType; var oldInfo = await _modelFieldService.GetByName(model.Name, model.ModelNum); if (oldInfo != null && oldInfo.Id != info.Id) { return(HandleResult.Error("名称已存在")); } } info.Explain = model.Explain; info.Options = model.Options; var res = isUpdate ? await _modelFieldService.Update(info) : await _modelFieldService.Add(info); if (res.IsSuccess && !isUpdate) { await _modelFieldService.CreateField(info); } return(res); }
public void InsertBulkTest() { var results = ModelField.InsertBulk(MockDb.Object, new List <ModelField>() { new ModelField() { ModelId = 1 } } ); Assert.IsTrue(results.Success); }
private void RenderInverseProperty(ModelField field) { if (field.ResolvedInverseName != null) { var accessorName = field.AccessorName.Pascalize() .Replace(field.ForeignKey.RefersTo.Model.Name.Pascalize(), _model.Name.Pascalize()); _generator.AppendLine($"/// <summary>") .AppendLine($"/// Gets or sets the inverse-related list of <see cref=\"{field.Model.Name.Pascalize()}\"/>") .AppendLine($"/// /summary>") .AppendLine($"[InverseProperty(nameof({field.AccessorName.Pascalize()}))]") .AppendLine($"public virtual ICollection<{field.Model.Name.Pascalize()}> {field.ResolvedInverseName} {{ get; set; }}") .EnsureEmptyLine(); } }
public void GetFieldsByModelIdTest() { MockDb.Setup(x => x.Fetch <ModelField>(It.IsAny <string>(), It.IsAny <object[]>())).Returns(new List <ModelField>() { new ModelField() { ModelFieldId = 1 } }); var results = ModelField.GetFieldsByModelId(MockDb.Object, 1); Assert.AreEqual(1, results.Item[0].ModelFieldId); }
private Store BuildStore(DataTable dt) { Store store = new Store(); Model md = new Model(); for (int i = 0; i < dt.Columns.Count; i++) { ModelField mdf = new ModelField(dt.Columns[i].ToString()); md.Fields.Add(mdf); } store.Model.Add(md); store.DataSource = dt; return(store); }
private void RenderInverseField(ModelField field) { if (field.ResolvedInverseName != null) { _generator.AppendLine($"Connection<ListGraphType<{field.ForeignKey.RefersTo.Model.Name.Pascalize()}Type>>()") .IncreaseIndentation() .AppendLine($".Name(\"{field.ResolvedInverseName.Underscore()}\")") .AppendLine($".Resolve(ctx => ") .BeginBlock() .AppendLine($"var schemaContext = ({_model.Project.Name.Pascalize()}Schema.Context)ctx.UserContext;") .AppendLine($"return schemaContext.Database.{field.Model.Name.Pascalize().Pluralize()}.Where(x => x.{field.Name.Pascalize()} == ctx.Source.{field.ForeignKey.RefersTo.Name.Pascalize()});") .EndBlock("});") .DecreaseIndentation(); } }
public void StopGame(ModelField ModelField, Form1 Form1) { // оставновка программы, если во вселенной не осталось жизни int SummAllField = 0; for (int i = 1; i < ModelField.X - 1; i++) { for (int j = 1; j < ModelField.Y - 1; j++) { SummAllField += ModelField.ReadSquareValueByCoordinate(i, j); } } if (SummAllField == 0) { // останавливаем таймер Form1.timer1.Stop(); // делаем таймер недоступным Form1.timer1.Enabled = false; } // оставновка программы, если во вселенной складываются устойчивые комбинации int EndOfGame1 = 0; int EndOfGame2 = 0; for (int i = 0; i < ModelField.X; i++) // сравнение массивов на 2х и 3х последних шагах { for (int j = 0; j < ModelField.Y; j++) { if (ModelField.ReadSquareValueByCoordinateOnLastGen(i, j) == ModelField.ReadSquareValueByCoordinate(i, j)) { EndOfGame1++; } if (ModelField.ReadSquareValueByCoordinate(i, j) == ModelField.ReadSquareValueByCoordinateOnPenultGen(i, j)) { EndOfGame2++; } } } if (EndOfGame1 == ModelField.X * ModelField.Y || EndOfGame2 == ModelField.X * ModelField.Y) { // останавливаем таймер Form1.timer1.Stop(); // делаем таймер недоступным Form1.timer1.Enabled = false; } }
private IEnumerable <ModelField> StandartModelFieldsItems(FilterHtmlGenerator.Filter filterData) { var modelFieldId = new ModelField("id", ModelFieldType.String) { ServerMapping = string.IsNullOrEmpty(filterData.SelectKeyValueColumn) ? "Value" : "Item." + filterData.SelectKeyValueColumn }; return(new List <ModelField> { modelFieldId, new ModelField("RowName", ModelFieldType.String) { ServerMapping = "Name" } }); }
public static Expression BuildPlan <T>(Expression provider, object translation, IList <BsonDocument> pipeline) { if (ModelField == null && BuildPlanMethod == null) { var assembly = typeof(IMongoDatabase).Assembly; ModelField = translation.GetPrivateField("_model"); BuildPlanMethod = assembly.GetTypes() .FirstOrDefault(type => type.Name == "ExecutionPlanBuilder") .GetMethod("BuildPlan", BindingFlags.Public | BindingFlags.Static); } var modelvalue = ModelField.GetValue(translation); StagesField = modelvalue.GetPrivateField("_stages"); pipeline = pipeline.Concat((IEnumerable <BsonDocument>)StagesField.GetValue(modelvalue)).ToList().AsReadOnly(); StagesField.SetValue(modelvalue, pipeline); return((Expression)BuildPlanMethod.Invoke(null, new object[] { provider, translation })); }
void SetForeignkey(NavigationProperty foreignkeyProp, NavigationProperty otherEnd) { otherEnd.IsForeignkey = false; var otherEndForeignkeyColumn = otherEnd.ModelClass.Fields.Find(f => f.Name == otherEnd.ForeignkeyColumn); if (otherEndForeignkeyColumn != null) { otherEndForeignkeyColumn.Delete(); } otherEnd.ForeignkeyColumn = null; foreignkeyProp.IsForeignkey = true; foreignkeyProp.ForeignkeyColumn = ModelUtil.GetMemberName(otherEnd.ModelClass.Name + "Id", foreignkeyProp.ModelClass, false); var otherEndPrimaryKeyField = otherEnd.ModelClass.Fields.Find(f => f.IsPrimaryKey); var newForeignkeyField = new ModelField(foreignkeyProp.Store) { Name = foreignkeyProp.ForeignkeyColumn }; CopyAttributesFrom(otherEndPrimaryKeyField, newForeignkeyField); foreignkeyProp.ModelClass.Fields.Add(newForeignkeyField); }
/// <summary> /// 初始化查询 明细列表 /// </summary> /// <param name="grid"></param> public void IniSelectDetailGrid(Ext.Net.GridPanel grid) { #region 分页每页数量 var pagesize = uiHelper.Select.DetailGrid.PageSize; if (pagesize <= 0) { pagesize = 15; } grid.GetStore().PageSize = pagesize; #endregion string prefix = UiControlNamePrefix.SelectDetailGrid; Model model = grid.GetStore().ModelInstance; #region 网格条数信息 int havecount = grid.ColumnModel.Columns.Count; RowNumbererColumn numbercol = new RowNumbererColumn(); numbercol.Width = 40; grid.ColumnModel.Columns.Insert(grid.ColumnModel.Columns.Count - havecount, numbercol); #endregion #region 添加设置字段 foreach (GridColumn column in uiHelper.Select.DetailGrid.Columns) { ModelField mField = new ModelField(); mField.Name = column.ColumnName; if (column.ColumnType == GridColumnType.Date) { mField.Type = ModelFieldType.Date; } model.Fields.Add(mField); if (column.IsShow) { CellCommandColumn cell = IniGridColumn(prefix, column); grid.ColumnModel.Columns.Insert(grid.ColumnModel.Columns.Count - havecount, cell); } } #endregion }
void CopyAttributesFrom(ModelField source, ModelField target) { target.DefaultValue = source.DefaultValue; target.IsFixedLength = source.IsFixedLength; target.IsUnicode = source.IsUnicode; target.MaxLength = source.MaxLength; target.Nullable = source.Nullable; target.Type = source.Type; }
void SetForeignkey(NavigationProperty foreignkeyProp, NavigationProperty otherEnd) { otherEnd.IsForeignkey = false; var otherEndForeignkeyColumn = otherEnd.ModelClass.Fields.Find(f => f.Name == otherEnd.ForeignkeyColumn); if (otherEndForeignkeyColumn != null) otherEndForeignkeyColumn.Delete(); otherEnd.ForeignkeyColumn = null; foreignkeyProp.IsForeignkey = true; foreignkeyProp.ForeignkeyColumn = ModelUtil.GetMemberName(otherEnd.ModelClass.Name + "Id", foreignkeyProp.ModelClass, false); var otherEndPrimaryKeyField = otherEnd.ModelClass.Fields.Find(f => f.IsPrimaryKey); var newForeignkeyField = new ModelField(foreignkeyProp.Store) { Name = foreignkeyProp.ForeignkeyColumn }; CopyAttributesFrom(otherEndPrimaryKeyField, newForeignkeyField); foreignkeyProp.ModelClass.Fields.Add(newForeignkeyField); }