Esempio n. 1
0
 /// <summary>
 /// 删除一条数据
 /// </summary>
 /// <param name="keyValue"></param>
 /// <returns></returns>
 public int Delete(int keyValue)
 {
     return(SqlHelper.ExecuteSql(
                "delete from " + TableName + " where " + KeyName + "=@" + KeyName,
                ParameterHelp.ParmsByWrite(new string[] { KeyName }, new object[] { keyValue })
                ));
 }
Esempio n. 2
0
        /// <summary>
        /// 根据ID返回填充后的实体类
        /// </summary>
        /// <param name="ID">主键ID</param>
        /// <returns>返回实体类</returns>
        public T GetModule(int ID)
        {
            //实例化实体类
            T TM = new T();

            //从数据库读取
            if (ID > 0)
            {
                DataTable dt = SqlHelper.Query("select * from " + TableName + " where " + KeyName + "=@" + KeyName, ParameterHelp.ParmsByWrite(new string[] { KeyName }, new object[] { ID })).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    object obj;
                    if (propArray != null)
                    {
                        obj = ModuleHelp.GetEntity
                              (
                            TM,
                            dt.Rows[0],
                            propArray
                              );
                    }
                    //读取的数据填充TM
                    else
                    {
                        obj = ModuleHelp.GetEntity
                              (
                            TM,
                            dt.Rows[0]
                              );
                    }
                    TM = (T)obj;
                }
                else
                {
                    TM = (T)ModuleHelp.GetEntity(TM);
                }
            }
            //不从数据取,自动补充值
            else
            {
                TM = (T)ModuleHelp.GetEntity(TM);
            }
            return(TM);
        }