Ejemplo n.º 1
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public DataService.Model.UserInfo DataRowToModel(DataRow row)
 {
     DataService.Model.UserInfo model = new DataService.Model.UserInfo();
     if (row != null)
     {
         if (row["UserID"] != null && row["UserID"].ToString() != "")
         {
             model.UserID = int.Parse(row["UserID"].ToString());
         }
         if (row["RoleID"] != null && row["RoleID"].ToString() != "")
         {
             model.RoleID = int.Parse(row["RoleID"].ToString());
         }
         if (row["UserGuid"] != null)
         {
             model.UserGuid = row["UserGuid"].ToString();
         }
         if (row["UserName"] != null)
         {
             model.UserName = row["UserName"].ToString();
         }
         if (row["Pwd"] != null)
         {
             model.Pwd = row["Pwd"].ToString();
         }
         if (row["RealName"] != null)
         {
             model.RealName = row["RealName"].ToString();
         }
         if (row["Sex"] != null)
         {
             model.Sex = row["Sex"].ToString();
         }
         if (row["IDCard"] != null)
         {
             model.IDCard = row["IDCard"].ToString();
         }
         if (row["Tel"] != null)
         {
             model.Tel = row["Tel"].ToString();
         }
         if (row["Status"] != null)
         {
             model.Status = row["Status"].ToString();
         }
         if (row["IntoTime"] != null && row["IntoTime"].ToString() != "")
         {
             model.IntoTime = DateTime.Parse(row["IntoTime"].ToString());
         }
         if (row["AddTime"] != null && row["AddTime"].ToString() != "")
         {
             model.AddTime = DateTime.Parse(row["AddTime"].ToString());
         }
     }
     return(model);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(DataService.Model.UserInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into UserInfo(");
            strSql.Append("UserID,RoleID,UserGuid,UserName,Pwd,RealName,Sex,IDCard,Tel,Status,IntoTime,AddTime)");
            strSql.Append(" values (");
            strSql.Append("@UserID,@RoleID,@UserGuid,@UserName,@Pwd,@RealName,@Sex,@IDCard,@Tel,@Status,@IntoTime,@AddTime)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserID",   SqlDbType.Int,        4),
                new SqlParameter("@RoleID",   SqlDbType.Int,        4),
                new SqlParameter("@UserGuid", SqlDbType.NVarChar,  50),
                new SqlParameter("@UserName", SqlDbType.NVarChar,  50),
                new SqlParameter("@Pwd",      SqlDbType.NVarChar,  50),
                new SqlParameter("@RealName", SqlDbType.NVarChar,  50),
                new SqlParameter("@Sex",      SqlDbType.NVarChar,  50),
                new SqlParameter("@IDCard",   SqlDbType.NVarChar,  50),
                new SqlParameter("@Tel",      SqlDbType.NVarChar,  50),
                new SqlParameter("@Status",   SqlDbType.NVarChar,  50),
                new SqlParameter("@IntoTime", SqlDbType.DateTime),
                new SqlParameter("@AddTime",  SqlDbType.DateTime)
            };
            parameters[0].Value  = model.UserID;
            parameters[1].Value  = model.RoleID;
            parameters[2].Value  = model.UserGuid;
            parameters[3].Value  = model.UserName;
            parameters[4].Value  = model.Pwd;
            parameters[5].Value  = model.RealName;
            parameters[6].Value  = model.Sex;
            parameters[7].Value  = model.IDCard;
            parameters[8].Value  = model.Tel;
            parameters[9].Value  = model.Status;
            parameters[10].Value = model.IntoTime;
            parameters[11].Value = model.AddTime;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DataService.Model.UserInfo GetModel(int UserID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 UserID,RoleID,UserGuid,UserName,Pwd,RealName,Sex,IDCard,Tel,Status,IntoTime,AddTime from UserInfo ");
            strSql.Append(" where UserID=@UserID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserID", SqlDbType.Int, 4)
            };
            parameters[0].Value = UserID;

            DataService.Model.UserInfo model = new DataService.Model.UserInfo();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(DataService.Model.UserInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update UserInfo set ");
            strSql.Append("RoleID=@RoleID,");
            strSql.Append("UserGuid=@UserGuid,");
            strSql.Append("UserName=@UserName,");
            strSql.Append("Pwd=@Pwd,");
            strSql.Append("RealName=@RealName,");
            strSql.Append("Sex=@Sex,");
            strSql.Append("IDCard=@IDCard,");
            strSql.Append("Tel=@Tel,");
            strSql.Append("Status=@Status,");
            strSql.Append("IntoTime=@IntoTime,");
            strSql.Append("AddTime=@AddTime");
            strSql.Append(" where UserID=@UserID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@RoleID",   SqlDbType.Int,        4),
                new SqlParameter("@UserGuid", SqlDbType.NVarChar,  50),
                new SqlParameter("@UserName", SqlDbType.NVarChar,  50),
                new SqlParameter("@Pwd",      SqlDbType.NVarChar,  50),
                new SqlParameter("@RealName", SqlDbType.NVarChar,  50),
                new SqlParameter("@Sex",      SqlDbType.NVarChar,  50),
                new SqlParameter("@IDCard",   SqlDbType.NVarChar,  50),
                new SqlParameter("@Tel",      SqlDbType.NVarChar,  50),
                new SqlParameter("@Status",   SqlDbType.NVarChar,  50),
                new SqlParameter("@IntoTime", SqlDbType.DateTime),
                new SqlParameter("@AddTime",  SqlDbType.DateTime),
                new SqlParameter("@UserID",   SqlDbType.Int, 4)
            };
            parameters[0].Value = model.RoleID;
            parameters[1].Value = model.UserGuid;
            parameters[2].Value = model.UserName;
            parameters[3].Value = model.Pwd;
            parameters[4].Value = model.RealName;
            parameters[5].Value = model.Sex;
            parameters[6].Value = model.IDCard;
            parameters[7].Value = model.Tel;
            parameters[8].Value = model.Status;
            if (model.IntoTime == null)
            {
                parameters[9].IsNullable = true;
                parameters[9].Value      = DBNull.Value;
            }
            else
            {
                parameters[9].Value = model.IntoTime;
            }

            parameters[10].Value = model.AddTime;
            parameters[11].Value = model.UserID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }