public static string CreateByType(IDbCommand command, BinaryExpression exp, EntityStruct obj) { var type = obj.Key; var tableName = CommonCommandBuilder.GetTableName(type); var cmdBulder = new StringBuilder(string.Format(@" UPDATE [{0}].[{1}].[{2}] ", command.Connection.Database, CommonCommandBuilder.DbSchemaName, tableName)); var nameValuePairs = CommonCommandBuilder.FieldByValueClauseBuilder(type, obj.Value); var parameterizatedNames = nameValuePairs.Select( x => new KeyValuePair <string, string>(x.Key, CommonCommandBuilder.GetParamsFormat(x.Key, x.Value, command.Connection.Database)) ); foreach (var pair in nameValuePairs) { var prop = CommonCommandBuilder.GetPropertyByAttrName(type, pair.Key); var parameter = command.CreateParameter(); parameter.ParameterName = CommonCommandBuilder.GetParamsFormat(pair.Key, pair.Value, command.Connection.Database); parameter.DbType = TypeMap[prop.PropertyType]; parameter.Value = pair.Value; if (!command.Parameters.Contains(parameter.ParameterName)) { command.Parameters.Add(parameter); } } var updateClause = string.Join(",", parameterizatedNames.Select(x => string.Format(" [{0}].[{1}] = {2}", tableName, x.Key, x.Value))); cmdBulder.Append(string.Format(" SET {0} WHERE {1}", updateClause.Trim(','), CommonCommandBuilder.BuildClauseByExpression(command, type, exp))); return(cmdBulder.ToString()); }
public static string Create(IDbCommand command, EntityStruct objPair) { var type = objPair.Key; var selectBody = CreateBody(command.Connection.Database, type); return(string.Format("{0} WHERE {1}", selectBody, FilterBuilder(command, objPair))); }
public void Update <T>(BinaryExpression exp, EntityStruct obj) where T : EntityBase, IEntity, new() { var handler = UpdateObjEvent; if (handler == null) { return; } handler(this, new UpdateObjsInfoEventArgs(exp, obj)); }
public void Remove(EntityStruct obj) { var handler = RemoveObjEvent; if (handler == null) { return; } handler(this, new RemoveObjInfoEventArgs(obj)); }
public void Add(EntityStruct obj) { var handler = AddObjEvent; if (handler == null) { return; } handler(this, new AddObjInfoEventArgs(obj)); }
private static string CreateByType(IDbCommand command, EntityStruct objPair) { var type = objPair.Key; var tableName = CommonCommandBuilder.GetTableName(type); var cmdBulder = new StringBuilder( string.Format(@" DELETE FROM [{0}].[{1}].[{2}] ", command.Connection.Database, CommonCommandBuilder.DbSchemaName, tableName)); cmdBulder.Append(CommonCommandBuilder.WhereByIdClause(command, type, objPair)); return(cmdBulder.ToString()); }
/*public virtual void SetStruct(EntityStruct es) { transform.position = es.position; _speed = es.speed; transform.rotation = Quaternion.AngleAxis(es.angle, Vector3.right); gameObject.SetActive(es.isActive); }*/ public virtual EntityStruct CreateStruct(Vector3 position,Vector3 ADirection,int EID, bool isactive) { var es = new EntityStruct(); es.position = position; es.speed = _speed; es.isActive = isactive; es.direction = ADirection; es.ID = EID; //es.angle = transform.localRotation.eulerAngles.z; //es.angle = Random.Range(0, 360); return es; }
public static string WhereByIdClause(IDbCommand command, Type type, EntityStruct obj) { var parameter = command.CreateParameter(); parameter.ParameterName = GetParamsFormat(IdFieldEntityName, obj.Value, command.Connection.Database); parameter.DbType = TypeMap[obj.Value.Id.GetType()]; parameter.Value = obj.Value.Id; if (!command.Parameters.Contains(parameter.ParameterName)) { command.Parameters.Add(parameter); } return(string.Format(" WHERE {0} = {1}", WhereBuilder(type, IdFieldEntityName), GetParamsFormat(IdFieldEntityName, obj.Value, command.Connection.Database))); }
/// <summary> /// 查询实体 /// </summary> /// <param name="ConditionForSelect">自定义条件</param> /// <param name="PageIndex">页索引号</param> /// <param name="PageSize">页行数</param> /// <param name="FieldNames">自定义字段</param> /// <returns>实体集合</returns> public EntitySet <T> Query(SQLCondition ConditionForSelect, int PageIndex, int PageSize, params string[] FieldNames) { EntityStruct es = EntityStructManager.GetEntityStruct(typeof(T)); int RecordCount = 0; DataSet ds = this.GetDSQuery(es.TableName, ConditionForSelect, PageIndex, PageSize, ref RecordCount, FieldNames); if (ds != null) { EntitySet <T> result = FillSetForDS(ds, es); result.RecordCount = RecordCount; return(result); } return(new EntitySet <T>()); }
/// <summary> /// 查询实体 /// </summary> /// <param name="ConditionForSelect">自定义条件</param> /// <param name="FieldNames">自定义字段</param> /// <returns>实体集合</returns> public EntitySet <T> Query(string ConditionForSelect, params string[] FieldNames) { EntityStruct es = EntityStructManager.GetEntityStruct(typeof(T)); DataSet ds = this.GetDSQuery(es.TableName, ConditionForSelect, FieldNames); if (ds != null) { EntitySet <T> result = FillSetForDS(ds, es); result.RecordCount = result.Count; return(result); } return(new EntitySet <T>()); }
private ICollection <T> ExecuteListReader <T>(EntityStruct objs) where T : EntityBase, IEntity, new() { Func <IDbCommand, EntityStruct, string> cmdBuilder = SelectCommandBulder.Create; ICollection <T> result; using (var conn = _connection) { using (var command = conn.CreateCommand()) { command.CommandText = cmdBuilder.Invoke(command, objs); command.CommandType = CommandType.Text; conn.Open(); result = command.ExecuteListReader <T>(); } } State = State.Close; return(result); }
public void Remove(EntityStruct obj) { if (obj.Value == null) { throw new ArgumentException(); } Func <IDbCommand, ICollection <EntityStruct>, string> cmdBuilder = DeleteCommandBuilder.Create; ExecuteNonQuery( new Dictionary <Func <IDbCommand, ICollection <EntityStruct>, string>, ICollection <EntityStruct> > { { cmdBuilder, new List <EntityStruct> { obj } } }); }
public void Update <T>(BinaryExpression exp, EntityStruct obj) where T : EntityBase, IEntity, new() { Func <IDbCommand, Dictionary <BinaryExpression, EntityStruct>, string> cmdBuilder = UpdateBySelectCommandBulder.Create; using (var conn = _connection) { using (var command = conn.CreateCommand()) { command.CommandText = cmdBuilder.Invoke(command, new Dictionary <BinaryExpression, EntityStruct> { { exp, obj } }); command.CommandType = CommandType.Text; conn.Open(); if (command.ExecuteNonQuery() < 1) { throw new ExecuteQueryException(command); } } } State = State.Close; }
private static string FilterBuilder(IDbCommand command, EntityStruct objPair) { var result = new StringBuilder(); foreach (var prop in ReflectionWrapper.GetPropertiesByFieldNamesAttrs(objPair.Key)) { if (CompareToDefault(GetDefault(prop.PropertyType), prop.GetValue(objPair.Value))) { var value = GetFieldValue(prop); var valueFormat = string.Format("@{0}", value); result.AppendFormat("{0} = {1} AND ", WhereBuilder(prop, objPair.Key), valueFormat); var parameter = command.CreateParameter(); parameter.ParameterName = valueFormat; parameter.DbType = TypeMap[prop.PropertyType]; parameter.Value = prop.GetValue(objPair.Value); command.Parameters.Add(parameter); } } var str = result.ToString(); return(str.Remove(str.Length - 4, 4)); }
/// <summary> /// 使用DataReader填充集合 /// </summary> /// <param name="type">实体类类型</param> /// <param name="dr">DataReader</param> /// <param name="ColumnNames"></param> private EntitySet <T> FillSetForDS(DataSet ds, EntityStruct es) { Type type = typeof(T); EntitySet <T> result = new EntitySet <T>(); foreach (DataRow dr in ds.Tables[0].Rows) { T instance = Activator.CreateInstance <T>();// (T)type.Assembly.CreateInstance(type.ToString()); foreach (DataColumn Column in ds.Tables[0].Columns) { try { string Key = Column.ColumnName.ToUpper(); if (dr[Key] == DBNull.Value) { continue; } #region 处理字段 Field Field = null; if (es.PKeyList.ContainsKey(Key)) { Field = es.PKeyList[Key]; } else if (es.FKeyList.ContainsKey(Key)) { Field = es.FKeyList[Key]; } else if (es.FieldList.ContainsKey(Key)) { Field = es.FieldList[Key]; } #endregion #region 赋值 if (Field != null) { if (Field.SerializedType == ESerializedType.NO) { if (Field.FieldType.IsEnum) { instance[Field.PropertyName] = Convert.ToInt32(dr[Key]); } else if (Field.FieldType.ToString() == "System.Boolean") { instance[Field.PropertyName] = Convert.ToBoolean(dr[Key]); } else { instance[Field.PropertyName] = dr[Key]; } } else { instance[Field.PropertyName] = Serialization.Deserialize(dr[Key], Field.FieldType, Field.SerializedType); } } else { instance[Key] = dr[Key]; } #endregion } catch { } } instance.IsCreated = true; instance.OPTag = EDBOperationTag.Ignore; result.Add(instance); } return(result); }
// Methods public Player(World world_, Texture2D cowTexture_, Texture2D texture_, Texture2D ButtonTexture, Vector2 ButtonPosition, float ButtonRotation, EntityStruct entityStruct_, float speed_, Quadrent quadrent_, int id_ = 999) { // Player constructor // ================ m_vehicle = new Vehicle(world_, texture_, entityStruct_); m_cow = new Sprite(cowTexture_, entityStruct_.GetPosition(), entityStruct_.GetRotationDegrees(), new Vector2(0.1f, 0.1f)); m_ReadyButton = new Button(ButtonTexture, ButtonPosition); m_ReadyButton.m_sprite.SetRotationDegrees(ButtonRotation); m_controlScheme = new ControlScheme(quadrent_); m_playerID = id_; m_currentCheckpoint = Checkpoint.First(Vector2.Zero); m_currentLap = 1; m_finished = false; m_ReadyUp = false; }
public ICollection <T> GetByFields <T>(EntityStruct obj) where T : EntityBase, IEntity, new() { return(ExecuteListReader <T>(obj)); }
private SoundEffectInstance go, carbrake; // ADDED // Methods public Vehicle(World world_, Texture2D texture_, EntityStruct entityStruct_) { // Vehicle constructor // ================ // Initialise the vehicle's main body m_vehicleBody = new Entity(world_, texture_, entityStruct_.GetPosition(), 0, BodyType.Dynamic, 10, 0.1f); m_vehicleBody.GetBody().AngularDamping = 1; m_vehicleBody.GetBody().LinearDamping = 1; // Initialise the vehicle's wheels Vector2 frontLeftPosition = FarseerPhysics.ConvertUnits.ToDisplayUnits(m_vehicleBody.GetPosition()) + new Vector2(-m_vehicleBody.GetSprite().GetWidth() / 2, -m_vehicleBody.GetSprite().GetHeight() / 2); m_vehicleTyres.Add(new Tyre(System.Input.Quadrent.TOP_LEFT, world_, frontLeftPosition, m_vehicleBody.GetRotationDegrees())); Vector2 frontRightPosition = FarseerPhysics.ConvertUnits.ToDisplayUnits(m_vehicleBody.GetPosition()) + new Vector2(m_vehicleBody.GetSprite().GetWidth() / 2, -m_vehicleBody.GetSprite().GetHeight() / 2); m_vehicleTyres.Add(new Tyre(System.Input.Quadrent.TOP_RIGHT, world_, frontRightPosition, m_vehicleBody.GetRotationDegrees())); Vector2 backLeftPosition = FarseerPhysics.ConvertUnits.ToDisplayUnits(m_vehicleBody.GetPosition()) + new Vector2(-m_vehicleBody.GetSprite().GetWidth() / 2, m_vehicleBody.GetSprite().GetHeight() / 2); m_vehicleTyres.Add(new Tyre(System.Input.Quadrent.BOTTOM_LEFT, world_, backLeftPosition, m_vehicleBody.GetRotationDegrees())); Vector2 backRightPosition = FarseerPhysics.ConvertUnits.ToDisplayUnits(m_vehicleBody.GetPosition()) - new Vector2(m_vehicleBody.GetSprite().GetWidth() / 2, m_vehicleBody.GetSprite().GetHeight() / 2); m_vehicleTyres.Add(new Tyre(System.Input.Quadrent.BOTTOM_RIGHT, world_, backRightPosition, m_vehicleBody.GetRotationDegrees())); // Create joints for each of the wheels to the body // Front Left m_frontLeftJoint = JointFactory.CreateRevoluteJoint(world_, m_vehicleBody.GetBody(), m_vehicleTyres[0].GetBody(), FarseerPhysics.ConvertUnits.ToSimUnits(new Vector2(-m_vehicleBody.GetSprite().GetWidth() / 2 * 0.8f, -m_vehicleBody.GetSprite().GetHeight() / 2 * 0.7f)), Vector2.Zero, false); m_frontLeftJoint.LowerLimit = Util.DegreesToRadians(-10); m_frontLeftJoint.UpperLimit = Util.DegreesToRadians(10); m_frontLeftJoint.LimitEnabled = true; m_frontLeftJoint.MotorEnabled = true; m_frontLeftJoint.MaxMotorTorque = 100; // Front right m_frontRightJoint = JointFactory.CreateRevoluteJoint(world_, m_vehicleBody.GetBody(), m_vehicleTyres[1].GetBody(), FarseerPhysics.ConvertUnits.ToSimUnits(new Vector2(m_vehicleBody.GetSprite().GetWidth() / 2 * 0.8f, -m_vehicleBody.GetSprite().GetHeight() / 2 * 0.7f)), Vector2.Zero, false); m_frontRightJoint.LowerLimit = Util.DegreesToRadians(-10); m_frontRightJoint.UpperLimit = Util.DegreesToRadians(10); m_frontRightJoint.LimitEnabled = true; m_frontRightJoint.MotorEnabled = true; m_frontRightJoint.MaxMotorTorque = 100; // Back left m_backLeftJoint = JointFactory.CreateRevoluteJoint(world_, m_vehicleBody.GetBody(), m_vehicleTyres[2].GetBody(), FarseerPhysics.ConvertUnits.ToSimUnits(new Vector2(-m_vehicleBody.GetSprite().GetWidth() / 2 * 0.8f, m_vehicleBody.GetSprite().GetHeight() / 2 * 0.7f)), Vector2.Zero, false); m_backLeftJoint.LowerLimit = 0; m_backLeftJoint.UpperLimit = 0; m_backLeftJoint.LimitEnabled = true; // Back right m_backRightJoint = JointFactory.CreateRevoluteJoint(world_, m_vehicleBody.GetBody(), m_vehicleTyres[3].GetBody(), FarseerPhysics.ConvertUnits.ToSimUnits(new Vector2(m_vehicleBody.GetSprite().GetWidth() / 2 * 0.8f, m_vehicleBody.GetSprite().GetHeight() / 2 * 0.7f)), Vector2.Zero, false); m_backLeftJoint.LowerLimit = 0; m_backLeftJoint.UpperLimit = 0; m_backRightJoint.LimitEnabled = true; m_vehicleBody.SetRotationDegrees(entityStruct_.GetRotationDegrees()); m_vehicleBody.UpdateSprites(); // AUDIO //TouchPanel.EnableMouseTouchPoint = true;//ADDED go = AudioHandler.vehicleEngine.CreateInstance(); //ADDED carbrake = AudioHandler.vehicleBrake.CreateInstance(); //ADDED }
public ICollection <T> GetByFields <T>(EntityStruct obj) where T : EntityBase, IEntity, new() { return(_dataSourceProvider.GetByFields <T>(obj)); }