⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dmovementactor.cs

📁 这是一个自动排课软件(包含源码,需求分析,详细设计).希望对你有所帮助.
💻 CS
📖 第 1 页 / 共 2 页
字号:
					}
		            if(searcher.MovementIDIsValid)
			        {
			            condition += " and Movement_ID=@Movement_ID_C";
			            cmd.Parameters.Add(new SqlParameter("@Movement_ID_C",searcher.MovementID));
					}
		            if(searcher.ActorIDIsValid)
			        {
			            condition += " and Actor_ID=@Actor_ID_C";
			            cmd.Parameters.Add(new SqlParameter("@Actor_ID_C",searcher.ActorID));
					}
					if(condition != string.Empty)
					{
						condition=" where"+condition.Substring(4);
					}
				    cmd.CommandText="update MovementActor set "+updateString.Substring(1)+condition;
                    result=cmd.ExecuteNonQuery();
                }
			}
			return result;
		}
		/// <summary>
        /// 根据查询对象构建过滤条件并使用事务的更新方法
        /// </summary>
		/// <param name="connection">实现共享Command的对象</param>
        /// <param name="searcher">查询对象</param>
		/// <param name="newValues">要更新的新值</param>
        /// <returns>影响的记录行数</returns>
	    public int Update(IConnection connection,MovementActorSearcher searcher,MovementActorSearcher newValues)
		{
		    string updateString = string.Empty;
		    string condition = string.Empty;
			SqlCommand cmd=connection.Command as SqlCommand;
			cmd.Parameters.Clear();
		    if(newValues.MovementActorIDIsValid)
			{
			    updateString += ",Movement_Actor_ID=@Movement_Actor_ID_V";
			    cmd.Parameters.Add(new SqlParameter("@Movement_Actor_ID_V",newValues.MovementActorID));
            }
		    if(newValues.MovementIDIsValid)
			{
			    updateString += ",Movement_ID=@Movement_ID_V";
			    cmd.Parameters.Add(new SqlParameter("@Movement_ID_V",newValues.MovementID));
            }
		    if(newValues.ActorIDIsValid)
			{
			    updateString += ",Actor_ID=@Actor_ID_V";
			    cmd.Parameters.Add(new SqlParameter("@Actor_ID_V",newValues.ActorID));
            }
		    if(searcher.MovementActorIDIsValid)
			{
			    condition += " and Movement_Actor_ID=@Movement_Actor_ID_C";
			    cmd.Parameters.Add(new SqlParameter("@Movement_Actor_ID_C",searcher.MovementActorID));
		    }
		    if(searcher.MovementIDIsValid)
			{
			    condition += " and Movement_ID=@Movement_ID_C";
			    cmd.Parameters.Add(new SqlParameter("@Movement_ID_C",searcher.MovementID));
		    }
		    if(searcher.ActorIDIsValid)
			{
			    condition += " and Actor_ID=@Actor_ID_C";
			    cmd.Parameters.Add(new SqlParameter("@Actor_ID_C",searcher.ActorID));
		    }
			if(condition != string.Empty)
			{
				condition=" where"+condition.Substring(4);
			}
		    cmd.CommandText="update MovementActor set "+updateString.Substring(1)+condition;
            return cmd.ExecuteNonQuery();
		}
		#endregion
		
		#region 查询实体集合
		/// <summary>
        /// 根据查询对象构建过滤条件查询
        /// </summary>
        /// <param name="searcher">查询对象</param>
        /// <returns>实体类对象列表</returns>
        public ArrayList Select(MovementActorSearcher searcher)
        {
            ArrayList entities = new ArrayList();
			string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
			using(SqlConnection conn=new SqlConnection(connectionString))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
					entities = Select(cmd,searcher);
				}
            }
			return entities;
        }
		/// <summary>
        /// 使用事务并且依据查询对象构建过滤条件查询
        /// </summary>
		/// <param name="connection">实现共享Command的对象</param>
        /// <param name="searcher">查询对象</param>
        /// <returns>实体类对象列表</returns>
        public ArrayList Select(IConnection connection, MovementActorSearcher searcher)
        {
		    SqlCommand cmd=connection.Command as SqlCommand;
            return Select(cmd,searcher);
        }
		public ArrayList Select(SqlCommand command,MovementActorSearcher searcher)
		{
		    string condition=string.Empty;
		    command.Parameters.Clear();
			ArrayList entities = new ArrayList();
		    if(searcher.MovementActorIDIsValid)
			{
			    condition += " and Movement_Actor_ID=@Movement_Actor_ID_C";
			    command.Parameters.Add(new SqlParameter("@Movement_Actor_ID_C",searcher.MovementActorID));
		    }
		    if(searcher.MovementIDIsValid)
			{
			    condition += " and Movement_ID=@Movement_ID_C";
			    command.Parameters.Add(new SqlParameter("@Movement_ID_C",searcher.MovementID));
		    }
		    if(searcher.ActorIDIsValid)
			{
			    condition += " and Actor_ID=@Actor_ID_C";
			    command.Parameters.Add(new SqlParameter("@Actor_ID_C",searcher.ActorID));
		    }
			if(condition != string.Empty)
			{
				condition=" where"+condition.Substring(4);
			}
			
            command.CommandText = "select * from MovementActor"+condition;
            return ExcuteSelectCommand(command);
		}
		/// <summary>
        /// 执行Command获取对象列表
        /// </summary>
        /// <param name="cmd">Command对象</param>
        /// <returns>实体类对象列表</returns>
        private ArrayList ExcuteSelectCommand(SqlCommand cmd)
        {
            ArrayList entities = new ArrayList();
            using (SqlDataReader dr = cmd.ExecuteReader())
            {
                while (dr.Read())
                {
                    MovementActor  entity = DataReaderToEntity(dr);
                    entities.Add(entity);
                }
            }
			SetForeignKeyEntity(cmd, ref entities);
			return entities;
        }
		private void SetForeignKeyEntity(SqlCommand command, ref ArrayList entities)
		{
		    //由外键获取相关实体
			DEmployee dEmployee=new DEmployee();
			DMovement dMovement=new DMovement();
			foreach(MovementActor  entity in entities)
			{
	            entity.Employee = dEmployee.SelectSingle(command,entity.ActorID);
	            entity.Movement = dMovement.SelectSingle(command,entity.MovementID);
			}
		}
        /// <summary>
        /// 查询所有实体
        /// </summary>
        /// <returns>实体类对象列表</returns>
        public ArrayList Select()
        {
            ArrayList entities = new ArrayList();
			string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
			using(SqlConnection conn=new SqlConnection(connectionString))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "select * from MovementActor";
                    entities=ExcuteSelectCommand(cmd);
                }
                return entities;
            }
        }
		/// <summary>
        /// 使用事务查询查询所有实体
        /// </summary>
		/// <param name="connection">实现共享Command的对象</param>
        /// <param name="searcher">查询对象</param>
        /// <returns>实体类对象列表</returns>
        public ArrayList Select(IConnection connection)
        {
            ArrayList entities = new ArrayList();
            SqlCommand cmd=connection.Command as SqlCommand;
			cmd.Parameters.Clear();
            cmd.CommandText = "select * from MovementActor";
            return ExcuteSelectCommand(cmd);
        }
		#endregion
		
		#region 查询单个实体
		/// <summary>
        /// 按主键字段查询特定实体
        /// </summary>
        /// <param name="pkValue">主键值</param>
        /// <returns>实体类对象</returns>
        public MovementActor SelectSingle(object pkValue)
        {
		    MovementActor entity=null;
			string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
			using(SqlConnection conn=new SqlConnection(connectionString))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    entity=SelectSingle(cmd,pkValue);
                }   
            } 
			return entity;
        }
		
		/// <summary>
        /// 使用事务并按主键字段查询特定实体
        /// </summary>
        /// <param name="pkValue">主键值</param>
        /// <returns>实体类对象</returns>
        public MovementActor SelectSingle(IConnection connection,object pkValue)
        {
		    SqlCommand cmd=connection.Command as SqlCommand;
			return SelectSingle(cmd,pkValue);
            
        }
		public MovementActor SelectSingle(SqlCommand command,object pkValue)
		{
		    MovementActor entity=null;
		    command.Parameters.Clear();
		    command.CommandText = "select * from MovementActor where Movement_Actor_ID=@pk";
			command.Parameters.Add(new SqlParameter("@pk",pkValue));
			using (SqlDataReader dr = command.ExecuteReader())
            {
			    if(dr.Read())
				    entity = DataReaderToEntity(dr);
			}
						
			//由外键获取相关实体
			DEmployee dEmployee=new DEmployee();
			DMovement dMovement=new DMovement();
	        entity.Employee = dEmployee.SelectSingle(command,entity.ActorID);
	        entity.Movement = dMovement.SelectSingle(command,entity.MovementID);
            return entity;
		}
		#endregion
		
				
		/// <summary>
        /// 从DataReader中取出值生成实体对象
        /// </summary>
        /// <param name="searcher">查询对象</param>
        /// <returns>过滤条件字符串</returns>
		private MovementActor DataReaderToEntity(SqlDataReader dr)
		{
		    MovementActor entity = new MovementActor ();
			if(dr["Movement_Actor_ID"]!=System.DBNull.Value)
			{
			    entity.MovementActorID=Convert.ToInt32(dr["Movement_Actor_ID"]);
			}
			if(dr["Movement_ID"]!=System.DBNull.Value)
			{
			    entity.MovementID=Convert.ToInt32(dr["Movement_ID"]);
			}
			if(dr["Actor_ID"]!=System.DBNull.Value)
			{
			    entity.ActorID=Convert.ToInt32(dr["Actor_ID"]);
			}
			return entity;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -