/// <summary> /// 得到一个对象实体 /// </summary> public Mxm.Model.users GetModel(int uid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select uid,username,password,sex,email,mobile,tel,last_login_time,reg_time,qq,msn,status from users "); strSql.Append(" where uid=@uid "); SqlParameter[] parameters = { new SqlParameter("@uid", SqlDbType.Int, 4) }; parameters[0].Value = uid; Mxm.Model.users model = new Mxm.Model.users(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["uid"].ToString() != "") { model.uid = int.Parse(ds.Tables[0].Rows[0]["uid"].ToString()); } model.username = ds.Tables[0].Rows[0]["username"].ToString(); model.password = ds.Tables[0].Rows[0]["password"].ToString(); if (ds.Tables[0].Rows[0]["sex"].ToString() != "") { if ((ds.Tables[0].Rows[0]["sex"].ToString() == "1") || (ds.Tables[0].Rows[0]["sex"].ToString().ToLower() == "true")) { model.sex = true; } else { model.sex = false; } } model.email = ds.Tables[0].Rows[0]["email"].ToString(); model.mobile = ds.Tables[0].Rows[0]["mobile"].ToString(); model.tel = ds.Tables[0].Rows[0]["tel"].ToString(); if (ds.Tables[0].Rows[0]["last_login_time"].ToString() != "") { model.last_login_time = DateTime.Parse(ds.Tables[0].Rows[0]["last_login_time"].ToString()); } if (ds.Tables[0].Rows[0]["reg_time"].ToString() != "") { model.reg_time = DateTime.Parse(ds.Tables[0].Rows[0]["reg_time"].ToString()); } model.qq = ds.Tables[0].Rows[0]["qq"].ToString(); model.msn = ds.Tables[0].Rows[0]["msn"].ToString(); if (ds.Tables[0].Rows[0]["status"].ToString() != "") { model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Mxm.Model.users model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update users set "); strSql.Append("username=@username,"); strSql.Append("password=@password,"); strSql.Append("sex=@sex,"); strSql.Append("email=@email,"); strSql.Append("mobile=@mobile,"); strSql.Append("tel=@tel,"); strSql.Append("last_login_time=@last_login_time,"); strSql.Append("reg_time=@reg_time,"); strSql.Append("qq=@qq,"); strSql.Append("msn=@msn,"); strSql.Append("status=@status"); strSql.Append(" where uid=@uid "); SqlParameter[] parameters = { new SqlParameter("@uid", SqlDbType.Int, 4), new SqlParameter("@username", SqlDbType.NVarChar, 50), new SqlParameter("@password", SqlDbType.NVarChar, 50), new SqlParameter("@sex", SqlDbType.Bit, 1), new SqlParameter("@email", SqlDbType.NVarChar, 500), new SqlParameter("@mobile", SqlDbType.NVarChar, 50), new SqlParameter("@tel", SqlDbType.NVarChar, 100), new SqlParameter("@last_login_time", SqlDbType.DateTime), new SqlParameter("@reg_time", SqlDbType.DateTime), new SqlParameter("@qq", SqlDbType.NVarChar, 50), new SqlParameter("@msn", SqlDbType.NVarChar, 200), new SqlParameter("@status", SqlDbType.Int, 4) }; parameters[0].Value = model.uid; parameters[1].Value = model.username; parameters[2].Value = model.password; parameters[3].Value = model.sex; parameters[4].Value = model.email; parameters[5].Value = model.mobile; parameters[6].Value = model.tel; parameters[7].Value = model.last_login_time; parameters[8].Value = model.reg_time; parameters[9].Value = model.qq; parameters[10].Value = model.msn; parameters[11].Value = model.status; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Mxm.Model.users model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into users("); strSql.Append("username,password,sex,email,mobile,tel,reg_time,qq,msn,status)"); strSql.Append(" values ("); strSql.Append("@username,@password,@sex,@email,@mobile,@tel,@reg_time,@qq,@msn,@status)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@username", SqlDbType.NVarChar, 50), new SqlParameter("@password", SqlDbType.NVarChar, 50), new SqlParameter("@sex", SqlDbType.Bit, 1), new SqlParameter("@email", SqlDbType.NVarChar, 500), new SqlParameter("@mobile", SqlDbType.NVarChar, 50), new SqlParameter("@tel", SqlDbType.NVarChar, 100), new SqlParameter("@reg_time", SqlDbType.DateTime), new SqlParameter("@qq", SqlDbType.NVarChar, 50), new SqlParameter("@msn", SqlDbType.NVarChar, 200), new SqlParameter("@status", SqlDbType.Int, 4) }; parameters[0].Value = model.username; parameters[1].Value = model.password; parameters[2].Value = model.sex; parameters[3].Value = model.email; parameters[4].Value = model.mobile; parameters[5].Value = model.tel; parameters[6].Value = model.reg_time; parameters[7].Value = model.qq; parameters[8].Value = model.msn; parameters[9].Value = model.status; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(-1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Mxm.Model.users GetModel(int uid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select uid,username,password,sex,email,mobile,tel,last_login_time,reg_time,qq,msn,status from users "); strSql.Append(" where uid=@uid "); SqlParameter[] parameters = { new SqlParameter("@uid", SqlDbType.Int,4)}; parameters[0].Value = uid; Mxm.Model.users model = new Mxm.Model.users(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["uid"].ToString() != "") { model.uid = int.Parse(ds.Tables[0].Rows[0]["uid"].ToString()); } model.username = ds.Tables[0].Rows[0]["username"].ToString(); model.password = ds.Tables[0].Rows[0]["password"].ToString(); if (ds.Tables[0].Rows[0]["sex"].ToString() != "") { if ((ds.Tables[0].Rows[0]["sex"].ToString() == "1") || (ds.Tables[0].Rows[0]["sex"].ToString().ToLower() == "true")) { model.sex = true; } else { model.sex = false; } } model.email = ds.Tables[0].Rows[0]["email"].ToString(); model.mobile = ds.Tables[0].Rows[0]["mobile"].ToString(); model.tel = ds.Tables[0].Rows[0]["tel"].ToString(); if (ds.Tables[0].Rows[0]["last_login_time"].ToString() != "") { model.last_login_time = DateTime.Parse(ds.Tables[0].Rows[0]["last_login_time"].ToString()); } if (ds.Tables[0].Rows[0]["reg_time"].ToString() != "") { model.reg_time = DateTime.Parse(ds.Tables[0].Rows[0]["reg_time"].ToString()); } model.qq = ds.Tables[0].Rows[0]["qq"].ToString(); model.msn = ds.Tables[0].Rows[0]["msn"].ToString(); if (ds.Tables[0].Rows[0]["status"].ToString() != "") { model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString()); } return model; } else { return null; } }