/// <summary> /// 执行外部模型的操作 /// </summary> /// <param name="model">外部的模型</param> /// <param name="operation">外部的模型的操作</param> /// <param name="arg">参数 arg的Model为源模型</param> /// <param name="id">外部模型的ID</param> /// <returns>生成的ObjectProxy</returns> public IObjectProxy ExcuteOperation(Model model, IOperation operation, IObjectProxy arg, object id) { //如果为空,返回默认值 //明天个性 //Set Value 如果为BusinisObject 返回默认值 ~~~ 笨的!!!! #region 初始化要操作的值,即要返回的值resultProxy var db = new SqlServer.dbContext((model.SqlCon == null ? model.Module.SqlCon : model.SqlCon), this.ContextFac); IObjectProxy resultproxy = null; if (operation == null) { return(db.GetDetail(model, id)); } List <object> invokeparams = new List <object>(); switch (operation.BaseOperationType) { case BaseOperationType.Create: resultproxy = new SqlDataProxy(model, this.ContextFac, LoadType.Null, this.Con); break; case BaseOperationType.Delete: case BaseOperationType.Update: resultproxy = db.GetDetail(model, id); break; default: return(null); } #endregion foreach (var command in operation.GetCommands().OrderBy(p => p.Index)) { switch (command.CommandsType) { case CommandsType.SetAccess: resultproxy.NotifyPropertyCanSet(command.Property, System.Convert.ToBoolean(command.Exp)); break; case CommandsType.SetValue: resultproxy[command.Property] = GetValue(command.Property, arg, command.Exp); break; case CommandsType.ExuteProprtyModelMethod: DynamicObject proxy = resultproxy[command.Property] as DynamicObject; object ob1 = new object(); proxy.TryInvokeMember(new ObjectInvokeMemberBinder(command.Exp), new object[] { } , out ob1); break; case CommandsType.ExuteOutModelMethod: var desmodel = this.ExcuteOperation( command.ArgModel, command.ArgModel.Operations.FirstOrDefault(p => p.Name.Trim().ToUpper() == command.Exp.Trim().ToUpper()), resultproxy, GetValue(command.Property, resultproxy, command.ArgSourceIdExp)); if (desmodel != null && command.Property != null) { resultproxy[command.Property] = GetValue(command.Property, desmodel, command.ArgPropertyExp); } break; case CommandsType.Filter: CheckCommand(command, resultproxy); break; default: break; } } var db2 = new SqlServer.dbContext((model.SqlCon == null ? model.Module.SqlCon : model.SqlCon), this.ContextFac); switch (operation.BaseOperationType) { case BaseOperationType.Create: db2.Create(resultproxy); break; case BaseOperationType.Delete: db2.Delete(resultproxy); break; case BaseOperationType.Update: db2.Save(resultproxy); break; default: break; } return(resultproxy); }
protected void SetDefaultValue(Property property, string value) { switch (property.PropertyType) { case PropertyType.Boolean: this[property] = Boolean.Parse(value.ToString().Trim()); return; case PropertyType.BusinessObject: if (string.IsNullOrEmpty(value) == false) { this[property] = new SqlDataProxy(property.Model, this.ConFac, LoadType.Null, this.Con) { ID = value } } ; else { this[property] = null; } return; case PropertyType.Byte: this[property] = byte.Parse(value); return; case PropertyType.Char: this[property] = char.Parse(value); return; case PropertyType.Date: case PropertyType.DateTime: this[property] = DateTime.Parse(value); return; case PropertyType.Decimal: this[property] = decimal.Parse(value); return; case PropertyType.Double: this[property] = double.Parse(value); return; case PropertyType.Enum: this[property] = int.Parse(value); return; case PropertyType.Float: this[property] = float.Parse(value); return; case PropertyType.Guid: this[property] = Guid.Parse(value); return; case PropertyType.IdentifyId: long ID = 0; long.TryParse(value, out ID); this[property] = ID; return; case PropertyType.Int: this[property] = int.Parse(value); return; case PropertyType.Long: this[property] = long.Parse(value); return; case PropertyType.MD5: this[property] = value; return; case PropertyType.Radom: this[property] = value; return; case PropertyType.RadomDECS: this[property] = value; return; case PropertyType.SerialNo: this[property] = value; return; case PropertyType.String: this[property] = value; return; case PropertyType.Time: this[property] = DateTime.Parse(value); return; case PropertyType.UInt: this[property] = uint.Parse(value); return; case PropertyType.ULong: this[property] = ulong.Parse(value); return; default: return; } }