Example #1
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);
        }
Example #2
0
        /// <summary>
        /// 添加并返回标志ID
        /// </summary>
        /// <param name="model">要添加的数据模型</param>
        /// <returns></returns>
        public int AddWithIdentity(T model)
        {
            object id = SqlHelper.ExecuteScalarText(AddTxt + " SELECT @@identity", ParameterHelp.ParmsByModule(model, propArray));

            return(Convert.ToInt32(id));
        }